开发者

imagerotate option before or after move upload in php

I have a form to upload a picture file, but i want to include an option to rotate the image in the same form.

What im not sure of, is should i rotate the image before saving it, or save it, open it, rotate it, then save it again. Im not sure what is the best method for accomplishing this. The code im using is below:

$imagename = uniqid().".jpg";
if (file_exists("upload/" . $imagename))
    {
        //echo $_FILES["file"]["name"] . " already exists. ";
    } else {
        // Rotate image here before saving?
        move_uploaded_file($_FILES["file"]["tmp_name"],"upload/" . $imagename);
        开发者_StackOverflow中文版// Or open/rotate/resave image here?
}


Always move the image first, then manipulate it. There are security restrictions in PHP that make it possible for a system administrator to say that only the move_uploaded_file() function is able to access an uploaded file in the temporary location and no other functions.

So, move it first, then manipulate. Otherwise your script will not work on servers that have this security enabled.


There is no real right or wrong answer here in my opinion. However I could see you running into issues with attempting to perform image manipulation on a tmp file (folder/file permissions, etc.).

Therefore you should move the image first, then after it is moved perform any image manipulation on it. This will help guarantee that you have the proper permissions to perform the image manipulation.


Basically when the picture is uploaded, it is already saved to a tempoary location. So either way you will open, rotate and save it. If it does not serve any purpose to save it to your local folder first, I would recommend to just open the temporary file, rotate it and save it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜