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...