I am working on an upload script that also resizes/rescales an image.
Currently it is working by uploading the image, moving to the upload dir (site.com/upload) and then resizing, and afterwards deleting the original again...
Now my question is: Can I do this without moving the original to the upload dir and even better, also keeping the new file in tmp so I the user can afterwards confirm the image (so If they don't want it and just hit the 'back' button it won't stay in the upload dir.)
Current code:
move_uploaded_file($_FILES['file']['tmp_name'], 'resize-upload/'.$_FILES['file']['name']);
$filename=$_FILES['file']['name'];
$Imagick=new Imagick();
$Imagick-> readImage('resize-upload/'.$filename);
$I开发者_运维知识库magick-> scaleImage(200,200,auto);
$Imagick-> writeImage('resize-upload/resized-'.$filename);
unlink('resize-upload/'.$filename);
You can't. You don't have the access to the image if you haven't moved it yet. But you can generate more than one thumbnail at a time from same image/object and if you are storing/keeping the original also then you don't need to unlink it either.
Another way would be to use flash and resize the image on the client side and then only save the resized image.
精彩评论