PHP File Upload Simple example, get the file name, type, size and other related information, complete the file upload, for everyone to learn reference.
1, upload the file code:
Code
<?php//determine if the temporary file storage path contains the user uploaded file if (Is_uploaded_file ($_files["UploadFile"] [ "Tmp_name"]) {//In order to be more efficient, store information in a variable $upfile=$_files["UploadFile"];//use an array type string to hold the information of the uploaded file//print_r ($upfile);// If you print, the output is similar to the array ([name] = = m.jpg [Type] = Image/jpeg [Tmp_name] and C:\WINDOWS\Temp\php1A.tmp [ERROR] = 0 [Size] = 44905) $name = $upfile ["Name"];//facilitates the later transfer of the file when the name $type= $upfile ["type"];//the types of uploaded files $size= $upfile ["Size"];// The size of the uploaded file $tmp_name= $upfile ["Tmp_name"];//the temporary name of the user to upload the file $error= $upfile ["Error"];////echo $name during the upload process;//To determine the file type, Determine if you want to transfer the file, if the requirements are set $ok=1 can be transferred switch ($type) {case "image/jpg": $ok =1; break; case "Image/jpeg": $ok =1; /gif ": $ok = 1; Break Default: $ok = 0; break;} If the file meets the requirements and there is no error during the upload process ($ok && $error = = ' 0 ') {//Call Move_uploaded_file () function, file transfer Move_uploaded_file ($tmp _ Name, ' up/'. $name); After the operation is successful, the prompt is successful, echo "";} else{//If the file does not conform to the type or the upload process has errors, the prompt fails echo "";}?
2. Submit a document form
Code
The above is a small series to share with you through the PHP simple example Introduction file upload, I hope you like.