I used php to write a simple page for uploading php files. it shows that the file has been uploaded successfully, but (1) files not uploaded under the corresponding directory [no files under the tmp directory, and no upload directories and files are generated ]. (2) parameter order of move_uploaded_file. the previous line in the code is incorrect, and the next line is correct, which is the opposite of that in the textbook. Solve the php file upload problem
I used php to write a simple file upload page, which shows that the upload is successful,
(1) files not uploaded in the corresponding directory [no files in the tmp directory, and no upload directories and files are generated ].
(2) parameter order of move_uploaded_file. the previous line in the code is incorrect, and the next line is correct, which is the opposite of that in the textbook.
Please try again.
Upload.html
Upload. php
If ($ _ FILES ["file"] ["error"]> 0)
{
Echo "Error:". $ _ FILES ["file"] ["error"]."
";
}
Else
{
Echo "Upload:". $ _ FILES ["file"] ["name"]."
";
Echo "Type:". $ _ FILES ["file"] ["type"]."
";
Echo "Size:". ($ _ FILES ["file"] ["size"]/1024). "KB
";
Echo "Stored in:". $ _ FILES ["file"] ["tmp_name"]."
";
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"]); // error
Move_uploaded_file ("upload/". $ _ FILES ["file"] ["name"], $ _ FILES ["file"] ["tmp_name"]);
Echo"
Storeed in: "." upload/". $ _ FILES [" file "] [" name "];
}
}
?>
Running result:
Upload: d.txt
Type: text/plain
Size: 2.439213125kb
Stored in: E: \ wamp \ tmp \ php4A7. tmp
Storeed in: upload/d.txt files uploaded by php are not generated and shared:
------ Solution --------------------
Move_uploaded_file returns a value. Check whether the method is successfully executed.
Path exists?
Write permission?
------ Solution --------------------
Does the current directory have an upload directory? You can create one first.