First, build a homepage
<! DOCTYPE html>"en">"UTF-8"> <title>Title</title>"Multipart/form-data"Refers to the encoding method for uploading multiple types of files and data streams--><form method="Post"action="123.php"Enctype="Multipart/form-data"> <input type="file"Name="file"> <input type="Submit"Value="Upload"></form></body>
Set up a new page to do upload processing
<?PHP//$types = [' Image/jpeg ', ' image/png '];if(!$_files['file']['Error']){ if($_files['file']['type'] =='Image/jpeg'){ if($_files['file']['size']<200000){//file to the folder, in order to prevent duplicate file name, you can splice timestamp, user name ...$file _name ="./upload/2017-10-31/". $_files['file']['name']; if(!file_exists ($file _name)) {Move_uploaded_file ($_files['file']['Tmp_name'], $file _name);//$filename =iconv ("UTF-8", "", $file _name);}Else{echo"Duplicate file name"; } }Else{echo"file too large"; } }Else{echo"file Format Error"; }}
Several points to be implemented in file processing
1. Are there any errors 2. The file type meets the requirements 3. Whether the file size meets the requirements 4. Duplicate file name
PHP File Upload