: This article describes how to upload files through a simple PHP example. if you are interested in the PHP Tutorial, refer to it. A simple example of PHP file upload is used to obtain the file name, type, size, and other information, and upload the file for your reference.
1,Upload filesCode:
Code
<? Php // Determine whether the temporary file storage path contains the user-uploaded file if (is_uploaded_file ($ _ FILES ["uploadfile"] ["tmp_name"]) {// for higher efficiency, store the information in the variable $ upfile =$ _ FILES ["uploadfile"]; // store the information with an array stringUpload files// Print_r ($ upfile ); // if printed, the output is similar to this information Array ([name] => m.jpg [type] => image/jpeg [tmp_name] => C: \ WINDOWS \ Temp \ php1A. tmp [error] => 0 [size] => 44905) $ name = $ upfile ["name"]; // name the object to be transferred later. $ type = $ upfile ["type"]; //Upload filesType $ size = $ upfile ["size"]; //Upload files$ Tmp_name = $ upfile ["tmp_name"]; // UserUpload filesThe temporary name $ error = $ upfile ["error"]; // The error message during the upload process // echo $ name; // you can determine the file type, determine whether to transfer the file. If yes, set $ OK = 1 to transfer switch ($ type) {case "image/jpg": $ OK = 1; break; case "image/jpeg": $ OK = 1; break; case "image/gif": $ OK = 1; break; default: $ OK = 0; break ;} // if the file meets the requirements and there is no error during the upload if ($ OK & $ error = '0') {// call the move_uploaded_file () function, file transfer move_uploaded_file ($ tmp_name, 'up /'. $ name); // after the operation is successful, the system prompts echo"