Distant_storm Posted December 19, 2007 Share Posted December 19, 2007 I plan to use this in a page as an example header("image/png"); < or whaterver it is imagefrompng("image.png"); ok now creating an image everytime a user see's the iamge or navigates to a new iamge. and destroying it after woudl this lay heavy on the server ? This is to stop image pathnames from being revealed Quote Link to comment https://forums.phpfreaks.com/topic/82401-processing-usage/ Share on other sites More sharing options...
corbin Posted December 19, 2007 Share Posted December 19, 2007 So are you trying to read the file from disk or generate an image and spit it out? If you're wanting to generate it, you could always cache it, and if you already have it on disk, the most effecient thing possible short of caching it in memory is just reading it out to the client. Quote Link to comment https://forums.phpfreaks.com/topic/82401-processing-usage/#findComment-418888 Share on other sites More sharing options...
Distant_storm Posted December 19, 2007 Author Share Posted December 19, 2007 can you please give an example of reading it out to the user Quote Link to comment https://forums.phpfreaks.com/topic/82401-processing-usage/#findComment-418929 Share on other sites More sharing options...
corbin Posted December 19, 2007 Share Posted December 19, 2007 $file = (isset($_GET['file'])) ? $_GET['file'] : false; if($file === false || str_pos($file, '/') !== false || str_pos($file, '\\') !== false) exit; //if the file isn't given or it has / or \ die if($handle = @fopen('files/' . $file) { while(!feof($handle)) { echo fread($handle, 8192); //read 8KB at a time } } else { //file not found or unable to open } The reason I would do it with fopen and fread there instead of file_get_contents is because with file_get_contents you load the entire file into PHP, and larger files could become cumbersome. Quote Link to comment https://forums.phpfreaks.com/topic/82401-processing-usage/#findComment-418946 Share on other sites More sharing options...
Distant_storm Posted December 19, 2007 Author Share Posted December 19, 2007 Would this be put in a file with header type as image and then called like <img src=make_image.php also the paths are checked and so do i just use the full path of the file ? Quote Link to comment https://forums.phpfreaks.com/topic/82401-processing-usage/#findComment-418964 Share on other sites More sharing options...
corbin Posted December 19, 2007 Share Posted December 19, 2007 OK.... Example time. Pretend the following Your web root is /html/ Your images are in /images/ Your wanting the file /images/image1.jpg You're at the page http://yoursite.com/images.php?file=image1.jpg To show /images/image1.jpg, images.php would need to look like this: $file = (isset($_GET['file'])) ? $_GET['file'] : false; if($file === false || str_pos($file, '/') !== false || str_pos($file, '\\') !== false) exit; //if the file isn't given or it has / or \ die if($handle = @fopen('/images/' . $file) { header("Content-type: image/jpeg"); while(!feof($handle)) { echo fread($handle, 8192); //read 8KB at a time } } else { //file not found or unable to open } So <img src="images.php?file=image1.jpg" /> Would correctly show the content from /images/image1.jpg. You would most likely want to make the Content-type change depending on the file extension by the way.... Quote Link to comment https://forums.phpfreaks.com/topic/82401-processing-usage/#findComment-418971 Share on other sites More sharing options...
corbin Posted December 19, 2007 Share Posted December 19, 2007 Grrr I think I had a brain lapse earlier... All of the fopen's should have 'r' as their second argument. (With the quotes) Quote Link to comment https://forums.phpfreaks.com/topic/82401-processing-usage/#findComment-418999 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.