1. Directory structure
2.index.php
= "File" > File name </label> <input type= "file" name= "file" id= "file" ><br> <input type= "Submit" value= " Submit "></form></body>
3.upload.php
<?PHP//upload file code//core code:/*if ($_files[' file ' [' Error ']>0) {echo ' errors: '. $_files[' file '] [' ERROR ']. ' <br> ';} else{echo ' upload file name: '. $_files[' file ' [' name ']. ' <br> '; echo ' filename type: '. $_files[' file ' [' type ']. ' <br> '; echo ' File size: '. ($_files[' file ' [' Size ']/1024). ' Kb<br> '; echo ' Files temporary storage address: '. $_files[' file ' [' Tem_name '];}*///the code required to upload the file, but before uploading, you need to determine the file limit, size, type, etc.//allow Shanghai to flee the picture suffix$allowedExts=Array("GIF", "JPEG", "JPG", "PNG");$temp=Explode(".",$_files["File"] ["name"]);//intercept file suffix$extension=End($temp);//file suffix$type=$_files["File"] ["Type"];$size=$_files["File"] ["Size"];$error=$_files["File"] ["Error"];$name=$_files["File"] ["Name"];$tmp _name=$_files["File"] ["Tmp_name"];if(($type= = "Image/gif") | | ($type= = "Image/jpeg") | | ($type= = "Image/jpg") | | ($type= = "Image/pjpeg") | | ($type= = "Image/x-png") | | ($type= = "Image/png") &&$size< 2048 &&In_array($extension,$allowedExts)) { if($error> 0) { Echo"Error:".$error. ' <br> '; } Else { Echo"File name:".$name. "<br>"; Echo"File type:".$type. "<br>"; Echo"File Size:". ($size/1024). "Kb<br>"; Echo"Temporary storage location:".$tmp _name; //determine whether the file exists in the directory where the file is stored, and if not, you need to create it, file's directory permission is 777 if(file_exists("file/".$name)) { Echo $name. "The file already exists. "; } Else { Move_uploaded_file($tmp _name, ' file/'.$name); Echo"File is stored in:". "file/".$name; } }} Else { Echo"Illegal Files";}
[Moka Classmate Code] PHP basic knowledge: Upload File source code