|
From: Mostafijur R. <mos...@ya...> - 2008-01-10 03:58:31
|
Hello
I want to plot data using GNUplot and want to show the graph file in the web browser using PHP.
Is it possible to plot data in GNUplot from PHP code and show into web browser?
If possible please can you tell me how.
Advance Thanks.
____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs |
|
From: Micha W. <mw...@gm...> - 2008-01-10 19:51:38
|
Mostafijur Rahman wrote: > I want to plot data using GNUplot and want to show the graph file in the web browser using PHP. I try to do the same with perl. BTW I think its gnuplot and has nothing to do with GNU (see "Does gnuplot have anything to do with the FSF and the GNU project?" <http://www.gnuplot.info/faq/faq.html#SECTION00037000000000000000> 1.7) > Is it possible to plot data in GNUplot from PHP code and show into web browser? You could add "<img src="/cgi-bin/plot.php?sin(x)"/> to your website and create a plot.php that calls gnuplot and make gnuplot output to standard out. Something like: print "Content-Type: image/png\n\n"; print `echo 'set term png; set output; plot sin(x)'|gnuplot`; But there is a HUGE PROBLEM, assume someone enters something like "< rm -rf" (with the quotes) (or ;`rm -rf` or something evil you did not think of yet). Assume futhermore you replace sin(x) with the input of the user (in our case "< rm -rf"), your plot command (which looks like plot "< rm -rf") would then delete files, so there is a HUGE SECURITY ISSUE. The only way of which I know to avoid this is by letting the user select between different functions to plot and have somthing like if input==A then plot sin(x) if input==B then plot cos(x) which is useless since you could create the plots in advance. > If possible please can you tell me how. Please be responsible and do not use the BROKEN CODE above! Micha |
|
From: jimineep <jam...@ho...> - 2008-01-11 13:58:10
|
I've just done it in perl/cgi so I don't see why php couldnt do it! I did it by saving off the data to a temporary .dat file, then running gnuplot from my script using this file, saving the output to a png file (jpeg might be possible...probably something like set term jpeg) and then getting my script to write an html output displaying this .png file. Im no expert in perl or gnuplot but it wasnt too tricky. A question for anyone who might know........is it possible for me to by pass saving off the temporary file and instead keeping a 2d array in memory and sending it straight to gnuplot Cheers -- View this message in context: http://www.nabble.com/Using-GNUplot%2C-plot-data-and-show-that-graph-into-web-browser.-tp14727326p14755136.html Sent from the Gnuplot - User mailing list archive at Nabble.com. |
|
From: Richard H. <r.h...@rl...> - 2008-01-11 14:24:45
|
jimineep wrote:
>
> I've just done it in perl/cgi so I don't see why php couldnt do it!
>
> I did it by saving off the data to a temporary .dat file, then running
> gnuplot from my script using this file, saving the output to a png file
> (jpeg might be possible...probably something like set term jpeg) and then
> getting my script to write an html output displaying this .png file. Im no
> expert in perl or gnuplot but it wasnt too tricky.
>
> A question for anyone who might know........is it possible for me to by
> pass saving off the temporary file and instead keeping a 2d array in
> memory and sending it straight to gnuplot
>
yes; one method is to write and read from stdin/stdout.
the code below (untested) uses this technique.
however, you should read up on piping to stdin reading from
stdout with perl: there are a number of issues to consider.
In addition, one must give consideration to security when
deploying gnuplot on a webserver.
hope this helps,
r,
--begin code example--
#
# call gnuplot into existence and render the commands, returning a binary blob
# from gnuplot. we use bidirectional communication.
# this has a problem in that we can't garentee to receive a result from our process
# in a timely manner.
# In short, if something goes wrong with gnuplot input, we will have to wait till
# apache kills the session. hopefully.
#
my $gnuplotCommands = "set term png; plot sin(x)";
#&errmsg("commands = '$gnuplotCommands'");
my $pid = open2(*Reader, *Writer, " gnuplot " ) or die "could not open $gnuplot: $!";
select *Writer;
$| = 1; # flush all writes down the pipe.
print Writer $gnuplotCommands or die "Could not write data to $gnuplot: $!";
close Writer or die "Ploblem closing $gnuplot, status=$?";
select STDOUT;
binmode(Reader);
my $buffer = "";
my $binaryPic = "";
while (read Reader, $buffer, 1024) {
$binaryPic .= $buffer;
}
close Reader or die "Problem closing $gnuplot, status=$?";
print 'Content-type: image/png; name"testfile"\n';
print 'Content-Disposition: filename="testfile.png';
print "\n\n";
print $binaryPic;
--end code example--
|