Copy codeThe Code is as follows:
<? Php
If ($ _ FILES ["file"] ["type"] = "image/gif ")
| ($ _ FILES ["file"] ["type"] = "image/jpeg ")
| ($ _ FILES ["file"] ["type"] = "image/pjpeg "))
& ($ _ FILES ["file"] ["size"] <20000 ))
{
If ($ _ FILES ["file"] ["error"]> 0)
{
Echo "Return Code:". $ _ FILES ["file"] ["error"]. "<br/> ";
}
Else
{
Echo "Upload:". $ _ FILES ["file"] ["name"]. "<br/> ";
Echo "Type:". $ _ FILES ["file"] ["type"]. "<br/> ";
Echo "Size:". ($ _ FILES ["file"] ["size"]/1024). "Kb <br/> ";
Echo "Temp file:". $ _ FILES ["file"] ["tmp_name"]. "<br/> ";
If (file_exists ("upload/". $ _ FILES ["file"] ["name"])
{
Echo $ _ FILES ["file"] ["name"]. "already exists .";
}
Else
{
Move_uploaded_file ($ _ FILES ["file"] ["tmp_name"], "upload/". $ _ FILES ["file"] ["name"]); // comment
Echo "Stored in:". "upload/". $ _ FILES ["file"] ["name"];
}
}
}
Else
{
Echo "Invalid file ";
}
?>
This is because a temporary folder exists in the PHP file during upload. If the temporary file is not moved, the temporary file will be automatically deleted after the script is complete.
Therefore, the above line of code is to save the uploaded file. The saved directory is the upload folder under the current directory.