dreamwest Posted November 20, 2009 Share Posted November 20, 2009 I want to pass an image to the browser then unlink() it Ive tried this but it doesnt work echo "<img src='image.jpg' border='0' />"; unlink('image.jpg'); Quote Link to comment https://forums.phpfreaks.com/topic/182229-unlink-image/ Share on other sites More sharing options...
emopoops Posted November 20, 2009 Share Posted November 20, 2009 are u on free host? cause well, theres some free hosts that dont allow unlinking. or something like that. also. if its an upload script u may want to use javascript to check for image validity as much as u can before u upload it to the site Quote Link to comment https://forums.phpfreaks.com/topic/182229-unlink-image/#findComment-961627 Share on other sites More sharing options...
Alex Posted November 20, 2009 Share Posted November 20, 2009 PHP just sends the HTML to the browser, it doesn't interpret the HTML, so it doesn't load the image. That's the job of the browser. So the reason it's not working is because by the time the browser tries to load the image (the php script has already sent the output and stopped executing) the image was unlinked and does no exist anymore. Quote Link to comment https://forums.phpfreaks.com/topic/182229-unlink-image/#findComment-961630 Share on other sites More sharing options...
dreamwest Posted November 20, 2009 Author Share Posted November 20, 2009 PHP just sends the HTML to the browser, it doesn't interpret the HTML, so it doesn't load the image. That's the job of the browser. So the reason it's not working is because by the time the browser tries to load the image (the php script has already send the output and stopped executing) the image was unlinked and does no exist anymore. Is there a way around this? Quote Link to comment https://forums.phpfreaks.com/topic/182229-unlink-image/#findComment-961632 Share on other sites More sharing options...
emopoops Posted November 20, 2009 Share Posted November 20, 2009 no i think the image wasnt unlinked, thats the reason the op posted Quote Link to comment https://forums.phpfreaks.com/topic/182229-unlink-image/#findComment-961633 Share on other sites More sharing options...
Alex Posted November 20, 2009 Share Posted November 20, 2009 I'm sure there's a way to accomplish what you want, but it depends on your specific situation. Can you explain what you're trying to do a bit better? I understand you're trying to output an image then unlink it, but in what context? Quote Link to comment https://forums.phpfreaks.com/topic/182229-unlink-image/#findComment-961636 Share on other sites More sharing options...
premiso Posted November 20, 2009 Share Posted November 20, 2009 To go along with what AlexWD said, one way to do it is create a script that spits out an image. the gist of it, readfile the image into a string, after that unlink the imagefile then use php to send the right headers and display the image to the browser. So instead of <img src="image.jpg" /> It would be <img src="yourimagescript.php?name=imagename.jpg" /> If you need a better example let me know, I am bored enough to write some code. Quote Link to comment https://forums.phpfreaks.com/topic/182229-unlink-image/#findComment-961638 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.