This article brings you the content is about how PHP upload files to the specified location (with code), there is a certain reference value, the need for friends can refer to, I hope to help you.
test.php (front-end code)
<! DOCTYPE html>
Explain:
do.php (from form processing file)
<?phpprint_r ($_files);?>
Explain:
Print_r () Outputs the data passed by the table only son as an array.
The output is:
Array ( [img] = = Array ( [name] + 1.jpg [Type] = Image/jpeg [Tmp_name] = C:\Windows\Temp\ Phpff07.tmp [ERROR] = 0 [size] = 17164 ))
Name: Names of uploaded files
Type: The MIME type of the uploaded file
Tmp_name: Temporary file name uploaded to server (or local)
Size: Sizes of uploaded files
Error: The wrong number of the upload file
do.php (Successful implementation of file upload to the specified folder)
Method One:
<?phpprint_r ($_files), $filename =$_files[' img ' [' name ']; $type =$_files[' img ' [' type ']; $tmp _name=$_files[' img ' [' Tmp_name ']; $size =$_files[' img ' [' size ']; $error =$_files[' img '] [' ERROR '];//move temporary files on the server to the specified directory Move_uploaded_ File ($tmp _name, "img/". $filename);
Where $_files is a file upload variable, storing the data uploaded by the file
Move_uploaded_file ($tmp _name, specify folder name. $filename);
Moves temporary files on the server to the specified directory, returns true successfully, fails to return false
Method Two:
Copy ($tmp _name, "img/". $filename);