// image upload handling $ upload_file = $ _ FILES [ 'upload_file'] [ 'tmp_name']; echo $ upload_file; $ upload_file_name = $ _ FILES [ 'upload_file'] [ 'name']; $ type = strstr ($ upload_file_name, ' . '); IF ($ upload_file == ") {$ newname =" 0.jpg ";} else {$ newname = $ newid. $ Type;} // $ newname = $ newid. $ Type;
$ INTONEW2 = "Update MMS_NEWS_INFO SET COL_IMAGE = '$ NEWNAME' WHERE COL_ID = '$ NEWID'"; MySQL_Query ($ INTONEW2, $ DB);
IF ($ upload_file) {$ file_size_max = 1000 * 1000; // 1M Limit file Upload Maximum Capacity (BYTES) $ store_dir = "neirongIMG /"; // Upload file storage position $ accept_overwrite = 1; // Whether to allow overwriting the same Document // Check file size if ($ upload_file_size> $ file_size_max) {echo "Sorry, your file capacity is greater than specified"; exit;}
// Check the read and write file IF (file_exists ($ store_dir. $ Upload_file_name) && $ accept_overwrite) {echo "file"; exit;}
// Copy the file to the specified directory IF (! Move_uploaded_File ($ UPLOAD_FILE, $ STORE_DIR. $ NEWNAME)) {echo "copy file failed";
}
Echo "
You uploaded the file:"; Echo $ _files ['UPLOAD_FILE'] ['Name']; echo "
"; // The original name of the client machine file.
The MIME type of the echo file is: "; echo $ _files ['UPLOAD_FILE'] ['type']; // file MIME type, you need to provide this information for the information, such as" image / gif ". Echo "
";
Echo "Upload File Size:"; Echo $ _Files ['UPLOAD_FILE'] ['size']; // The size of the file has been uploaded, the unit is byte. Echo "
";
The echo "file is uploaded after being temporarily stored as:"; Echo $ _files ['UPLOAD_FILE'] ['TMP_NAME']; // The file is stored in the server after being uploaded. Echo "
";
$ Erroe = $ _ files ['UPLOAD_FILE'] ['Error']; Switch ($ Erroe) {Case 0: Echo "Upload Success"; Break; Case 1: Echo "Uploaded files exceed php.ini UPLOAD_MAX_FILESIZE Option Limit The value. "; Break; Case 2: Echo" Uploaded file size exceeds the value specified by the max_file_size option in the HTML form. "; Break; Case 3: Echo" file only partially uploaded "; Break; Case 4: Echo" No file is uploaded "; Break;} // picture upload processing
"> About Error Messages Starting from PHP 4.2.0, PHP will return a corresponding error code along with the file information array. This code can be found in the ['ERROR'] field in the file array generated when the file is uploaded, that is, $ _files ['userfile'] ['Error'].
UPLOAD_ERR_OK Value: 0; No error occurred, file upload success.
Upload_err_ini_size value: 1; uploaded files exceed the value limit on the UPLOAD_MAX_FILESIZE option in php.ini.
UPLOAD_ERR_FORM_SIZE Value: 2; Uploaded file size exceeds the value specified in the html form.
UPLOAD_ERR_PARTIAL value: 3; file only has been uploaded.
UPLOAD_ERR_NO_FILE value: 4; No file is uploaded.
Note: These have become PHP constants after PHP 4.3.0. PHP accepts any files from a browser that meets RFC-1867 standards (including Netscape Navigator 3 and higher, Microsoft Internet Explorer 3 add Micro patch, or higher). This feature of PHP allows us to upload text files or upload binaries. With PHP authentication and file operation functions, you can control who has uploaded permissions, and how to proceed after the file is uploaded.
Related Settings: See the file_uploads, upload_max_filesize, upload_max_filesize, upload_tmp_filesize, pOST_MAX_SIZE settings options.
Note that PHP also supports file upload of the PUT method, the AMAYA client of Netscape Composer and W3C uses this method. Please refer to PUT method support for more information.
You can build a special form as follows to support file upload:
Example 18-1. File upload form