: This article mainly introduces php file upload. if you are interested in the PHP Tutorial, refer to it. UpLoad. php
The file size cannot exceed 2 MB ";}}?>
UpLoadProcess. php
2*1024*1024) {echo "the file is too large to upload files larger than 2 MB
"; Echo" back to re-upload "; exit () ;}$ file_type = $ _ FILES ['myfile'] ['type']; if ($ file_type! = "Image/jpg" & $ file_type! = "Image/pjpeg") {echo "the file type can only be jpg"; exit ();} // echo"";// print_r($_FILES);// echo "
"; If (is_uploaded_file ($ _ FILES ['myfile'] ['tmp _ name']) {// transfers the file to the desired directory; $ upLoaded_file = $ _ FILES ['myfile'] ['tmp _ name']; $ fileName = $ _ FILES ['myfile'] ['name']; // dynamically create a folder for each user $ user_path = $ _ SERVER ['document _ root']. "/fileOpt/upLoadFiles /". $ username; if (! File_exists ($ user_path) {mkdir ($ user_path);} // $ destPath = $ user_path. "/". $ fileName; $ destPath = $ user_path. "/". (time (). rand )). substr ($ fileName, strrpos ($ fileName ,". "); // if the target file exists, it will be overwritten if (move_uploaded_file ($ upLoaded_file, $ destPath )) {echo $ _ FILES ['myfile'] ['name']. "Upload successful! ";} Else {echo" Upload failed!
"; Echo" back to re-upload ";}} else {echo" Upload failed!
"; Echo" back to re-upload ";}?>
The above introduces php file uploading, including some content, and hope to be helpful to friends who are interested in PHP tutorials.