1. Configure the php.ini file
The following property values are primarily set:
2, pre-defined variables
The list is as follows:
Create an upload field to upload the file data via the _files variable output. The sample code is as follows:
"; } } ? >
The results of the operation are as follows:
3, File upload function
PHP uses the Move_uploaded_file () function to upload files with the following syntax:
BOOL Move_uploaded_file (string filename,string destination)
The function uploads the file to the specified location and returns True if successful, and false if it fails. parameter filename, temporary file name, $_file[tmp_name]; parameter destination is the new path and name saved after uploading.
The sample code is as follows:
The results of the operation are as follows:
4, multi-file upload
There are many ways to upload multiple files, we have evolved a multi-file upload based on a single file. The code examples are as follows:
"; if (Move_uploaded_file ($file 1[' tmp_name '), $file 1[' name ']) {echo "Upload succeeded
"; } else{echo "Upload failed
"; } } if ($file 2[' error '] = = UPLOAD_ERR_OK) {echo "path:". $file 2[' name ']. "
"; if (Move_uploaded_file ($file 2[' tmp_name '), $file 2[' name ']) {echo "Upload succeeded
"; } else{echo "Upload failed
"; } } if ($file 3[' error '] = = UPLOAD_ERR_OK) {echo "path:". $file 3[' name ']. "
"; if (Move_uploaded_file ($file 3[' tmp_name '), $file 3[' name ']) {echo "Upload succeeded
"; } else{echo "Upload failed
The results of the operation are as follows:
The sample code for the second way to upload multiple files is as follows:
$error) {if ($error ==upload_err_ok) {echo "filename:". $filearray [' name '] [$key]. "
"; if (Move_uploaded_file ($filearray [' tmp_name '] [$key], $filearray [' name '] [$key]) {echo "Upload succeeded
"; } else{echo "Upload failed
"; } } } ? >
The results of the operation are as follows:
In addition to the above two, there is a third way to upload multiple files, of course, I think the most perfect way, is to select multiple files at once to upload. The main thing is to use swfupload to achieve. Because my current knowledge is limited, I will study this together with everyone in the back.