Php image upload code example
| Php implements the image upload code, which can determine the file size, type, and generate the file name by year, month, day, minute, and second. this is suitable for beginners.
The code is as follows.
$ File_size_max) {echo "Sorry, your file capacity exceeds the limit"; exit;} // Check the read/write file if (file_exists ($ store_dir. $ upload_file_name) & $ accept_overwrite) {Echo "file with the same file name"; exit;} // copy the file to the specified directory if (! Move_uploaded_file ($ upload_file, $ store_dir. $ newname) {echo "file copy failed"; exit ;}} Echo"You uploaded the file: "; echo $ _ FILES ['upload _ file'] ['name']; echo" "; // The original name of the client machine file. Echo "the MIME type of the file is:"; echo $ _ FILES ['upload _ file'] ['type']; // The MIME type of the file, the browser must provide support for this information, such as "image/gif ". Echo" "; Echo" size of the uploaded file: "; echo $ _ FILES ['upload _ file'] ['size']; // size of the uploaded file, in bytes. Echo" "; Echo" the file is temporarily stored after being uploaded: "; echo $ _ FILES ['upload _ file'] ['tmp _ name']; // temporary file name stored on the server after the file is uploaded. Echo" "; $ Erroe = $ _ FILES ['upload _ file'] ['error']; switch ($ Erroe) {case 0: Echo" uploaded successfully "; break; case 1: Echo "the uploaded file exceeds php. the value of the upload_max_filesize option in ini. "; break; case 2: Echo" the size of the uploaded file exceeds the value specified by the MAX_FILE_SIZE option in the HTML form. "; Break; case 3: Echo" only part of the file is uploaded "; break; case 4: Echo" no file is uploaded "; break ;}// image Upload processing?> |