PHP file upload, _ PHP Tutorial

Source: Internet
Author: User
Tags upload php
Php file upload ,. Php file upload ,? Php $ allowtypearray (gif, png, jpg); set the supported Upload types to gif, png, and jpg $ size000000; set the size to 1 MB (1000000 bytes) upload php files,
 0) {echo 'upload error: '; switch ($ _ FILES ['myfile'] ['error']) {case 1: die ('upload file size exceeds the agreed value in the PHP configuration file: upload_max_filesize '); case 2: die ('upload file size exceeds the agreed value in the form: MAX_FILE_SIZE '); case 3: die ('file only partially upload'); case 4: die ('no file uploaded'); default: die ('last known error ');}} // Determine whether the uploaded file is of a sufficient file type. use the file extension $ hz = array_pop (explode (". ", $ _ FILES ['myfile'] ['name']); // determines whether the object is a sufficient file type by determining the file suffix. if (! In_array ($ hz, $ allowtype) {die ("this suffix is{$ Hz}, Not a sufficient file type! ");}/* You can also restrict the file upload type list ($ maintype, $ subtype) by obtaining the primary and subtypes in the MIME type of the uploaded file) = explode ("/", $ _ FILES ['myfile'] ['type']); if ($ maintype = "text") {// the Upload file cannot be uploaded due to the master limit, for example, .txt. html. php and other files die ('problem: you cannot upload text files. ');} * // Determines whether the uploaded file is a sufficient size. if ($ _ FILES ['myfile'] ['size']> $ size) {die ("more than enough{$ Size}Byte size ");} // for system security, and files of the same name will not be overwritten. After uploading, use the system-defined $ filename = date (" YmdHis ") file name "). rand (100,999 ). ". ". $ hz; // Determine whether the file is uploaded. if (is_uploaded_file ($ _ FILES ['myfile'] ['tmp _ name']) {if (! Move_uploaded_file ($ _ FILES ['myfile'] ['tmp _ name'], $ path. '/'. $ filename) {die ('problem: files cannot be moved to the specified directory. ') ;}} Else {die ("problem: uploading a file {$ _ FILES ['myfile'] ['name']} is not a legal file :");} // if the file is successfully uploaded, the echo file {$ upfile} is successfully uploaded and saved in the directory {$ path, the size is {$ _ FILES ['myfile'] ['size']} bytes ";

Success ,? Php $ allowtype = array ("gif", "png", "jpg"); // Set the supported Upload types to gif, png, and jpg $ size = 1000000; // Set the allowed size to less than 1 MB (1000000 bytes...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.