I've been searching the internets for a while and I can't seem to find any way to do this.
I'd like to have a script that allows users to upload images. It would modify the image in at least two ways and then return these image files to the visitor of the page. It's easy enough to allow file uploads (maybe not easy to secure it) but how can I ensure that uploaded files are not stored permanently on the server?
Serving temporary files
Moderator: General Moderators
-
GloriousEremite
- Forum Newbie
- Posts: 13
- Joined: Tue Aug 14, 2007 1:00 pm
Ok, I came up with the idea of sending the image to the browser using header("Content-type: image/jpeg") (for jpgs obviously), but it isn't working for some reason. Basically, I'm spawning a new window which should send the jpg to the browser, then delete the image file (not a particularly elegant solution, but I couldn't think of any other way).
Two questions:
1) Is it possible to display html along with the image this way? (I'm fairly sure it isn't, but I'd better ask)
2) Why does this only display the binary data, rather than the image:
Let's ignore the security concerns for a moment 
I get the same results whether the second two header lines are there, and the same result if the unlink line is omitted (ie, whether I delete the file or not). Am I mad or shouldn't this display an image?
Two questions:
1) Is it possible to display html along with the image this way? (I'm fairly sure it isn't, but I'd better ask)
2) Why does this only display the binary data, rather than the image:
Code: Select all
<?php
header("Content type: image/jpeg");
header('Content-transfer-encoding: binary');
header('Content-length: '.filesize($_GET['file']));
readfile($_GET['file']);
unlink($_GET['file']);
?>I get the same results whether the second two header lines are there, and the same result if the unlink line is omitted (ie, whether I delete the file or not). Am I mad or shouldn't this display an image?
1: No
2: The second header (transfer type) is set to binary mode. Other than that, it should technically work
Try this for images (jpgs only obviously)
2: The second header (transfer type) is set to binary mode. Other than that, it should technically work
Try this for images (jpgs only obviously)
Code: Select all
$im = imagecreatefromjpeg($_GET['file']);
imagejpeg($im);
imagedestroy($im);- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
-
GloriousEremite
- Forum Newbie
- Posts: 13
- Joined: Tue Aug 14, 2007 1:00 pm
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm