When using the form to upload a file, the form must be submitted by post, the input control of the upload file type property value should be file, most importantly, the form label needs to add a enctype= "Multipart/form-data" property. This article is mainly to share with you the PHP processing form upload file method, hope to help everyone.
HTML code:
<! DOCTYPE html>
PHP Code:
<?php/* * Use $_files to receive file data uploaded through the form *$_files[' File1 '] in file1 corresponding form in the input tag of the upload file in the name Value *$_files[' File1 '] An array is returned: $_files[' file1 ' [' name '] Displays the original name of the uploaded file. $_files[the MIME type of the ' file1 ' [' type '] file, such as "Image/gif", "Image/png". $_files[' file1 ' [' size '] the size of the uploaded file, in bytes. $_files[' file1 ' [' tmp_name '] stores temporary file names and temporary stored paths. $_files[' file1 ' [' Error '] and the file upload related error code. = 0; No error occurred and the file upload was successful. = 1; The uploaded file exceeds the value of the Upload_max_filesize option limit in php.ini. = 2; The size of the uploaded file exceeds the value specified by the Max_file_size option in the HTML form. = 3; Only part of the file is uploaded. = 4; No files were uploaded. = 5; The upload file size is 0. */$file =$_files[' file1 ']; Rename the file, try not to start the Chinese name, as follows timestamp + random number rename $filename =time (). rand (0,1000); Gets the suffix of the file, PathInfo () returns the path information of a file as an array, where the extension element is the suffix name of the file $ext =pathinfo ($_files[' file1 ' [' name ']) [' Extension ']; The final file name is $filename = $filename. '. '. $ext; Setting the location where the file is uploaded to the server, Move_uploaded_file () moves the file to the new location, the first parameter is the file to move, and the second parameter is where to move. I am here to put in the same directory as this PHP file, note the need to connect the new file name. if (mOve_uploaded_file ($file [' tmp_name '], './'. $filename)} {echo "Success"; } else{echo "error"; }?>