| 
<?php/**
 * example1.php
 *
 * this script provides a user to upload a PHP src file
 * and returns the resulting jpeg image
 */
 
 if (count($_FILES)) {
 if ($_FILES["file"]["error"] > 0) {
 echo "Error: " . $_FILES["file"]["error"] . "<br />";
 } else {
 show_graph();
 }
 } else {
 // no files uploaded
 show_form();
 }
 exit;
 
 function show_form()
 {
 print "<html>\n<body>\n";
 print "<h2>upload some php code</h2>\n";
 print '
 <form method="post"
 enctype="multipart/form-data">
 <label for="file">Filename:</label>
 <input type="file" name="file" id="file" />
 <br />
 <input type="submit" name="submit" value="Submit" />
 </form>';
 print "\n</body>\n</html>\n";
 
 }
 
 function show_graph()
 {
 require_once("dotwriter.inc.php");
 $c = new dotrunner();
 // need somewhere to write temp file and resulting jpeg
 $c->outputFileName=tempnam('graphs/','graph');
 
 $outfile=$c->genGraph(
 /* first param is the src code */
 file_get_contents($_FILES["file"]["tmp_name"]),
 /* 2nd param is a title for the graph - normally this would be the filename */
 'Uploaded');
 
 if (file_exists($outfile) && ($in=fopen($outfile, 'r'))) {
 header('Content-Type: image/jpeg');
 while($pt=fgets($in, 8096)) {
 print $pt;
 }
 fclose($in);
 unlink($outfile);
 } else {
 print "erm.....something went wrong?";
 }
 
 $c->cleanUp();
 
 }
 
 |