How do I force-download a dynamic image that requires arguments?

EJV

New Member
I have a dynamic image which uses GD to throw in some overlay images/text. This would be dynamicImage.php?firstName=Bob&lastName=Sacamano. I want to be prompted to download that file, so I created a download.php file to act as the middle-man:\[code\]//Get the Arguments$file .= "firstName=".filter_var($_GET['firstName'], FILTER_SANITIZE_STRING);$file .= "&lastName=".filter_var($_GET['lastName'], FILTER_SANITIZE_STRING);//get The File Size$size = intval(sprintf("%u", filesize($file)));//Header Info to Prompt for Download and name it a .jpgheader('Content-Description: File Transfer');header('Content-Type: application/octet-stream');header("Content-disposition: attachment; filename=dynamicImage.jpg");header("Content-Length: ".$size);readfile($file, true);//.$file);\[/code\]There's 2 problems, first I get this error:\[code\]PHP Warning: filesize() [<a href='http://stackoverflow.com/questions/3810398/function.filesize'>function.filesize</a>]: stat failed for dynamicImage.php?firstName=bob&lastName=Sacamano in /www/download.php on line 19PHP Warning: readfile(dynamicImage.php?firstName=bob&lastName=Sacamano) [<a href='http://stackoverflow.com/questions/3810398/function.readfile'>function.readfile</a>]: failed to open stream: No such file or directory in /www/download.php on line 25\[/code\]See how it parses the & to & ? But not only that. If I take out the arguments and just leave dynamicImage.php it prompts me to download the raw php file. Is there a way I can make it Run the PHP and then download the generated image?BTW My dynamicImage.php ends with:\[code\]header("Content-Type: image/JPEG");ImageJpeg ($bg);imagedestroy($bg);\[/code\]Fixd. I altered my dynamicImage.php thusly:\[code\]if(isset($_GET['download'])){ header('Content-Description: File Transfer'); header('Content-Type: application/octet-image'); header("Content-disposition: attachment; filename=dynamicImage.jpg");}else{ header("Content-Type: image/JPEG"); }ImageJpeg ($bg);imagedestroy($bg); \[/code\]
 
Back
Top