Php file, file upload: PHP file Upload implementation and introduction: Implementation and introduction in program annotations. File submission page: (you can submit the file to doAction. php, doAction1.php, and doAction2.php respectively for testing.) upload the upload. php file & lt; formactiondoActi implementation and introduction in the program annotations.
File submission page: (you can submit to doAction. php, doAction1.php, and doAction2.php respectively for testing)
Upload. php
File Upload
DoAction. php
DoAction1.php
DoAction2.php
$ MaxSize) {exit ('upload file oversized ');} echo $ fileInfo ['type']; exit; // $ ext = strtolower (end (explode ('. ', $ fileInfo ['name']); $ ext = pathinfo ($ fileInfo ['name'], PATHINFO_EXTENSION); if (! In_array ($ ext, $ allowExt) {exit ('invalid file type');} // checks whether the object is uploaded using http post. if (! Is_uploaded_file ($ fileInfo ['tmp _ name']) {exit ('file not uploaded through http post ');} // check whether the image type is true/** getimagesize ($ filename): obtain the information of the specified image, if it is an image array * if it is not an image (even if the file suffix is an image format, it is not actually an image), false is returned. */If ($ flag) {if (! Getimagesize ($ fileInfo ['tmp _ name']) {exit ('not a real image type'); }}$ path = 'upload '; // php uses mkdir to create a multi-level Directory http://www.daixiaorui.com/read/38.html /** Mkdir ($ path, 0777, true); * first parameter: required, indicating the path of the multi-level directory to be created; * second parameter: set directory permissions, the default value is 0777, which indicates the maximum possible access. * The third parameter: true indicates that multi-level directories can be created. * // ** The chmod () function changes the file mode. * If the call succeeds, TRUE is returned. otherwise, FALSE is returned. */If (! File_exists ($ path) {mkdir ($ path, 0777, true); // 0777 indicates readable and writable chmod ($ path, 0777);} // ensure file name displacement, place duplicate names to generate overwrite/** uniqid () function generates a unique ID based on the current time in microseconds. * Syntax * uniqid (prefix, more_entropy) * parameter description * prefix is optional. It is the prefix specified by ID. This parameter is useful if two scripts generate IDs exactly in the same microsecond. * More_entropy is optional. Specify more entropy at the end of the returned value. * // ** Microtime () returns the current Unix timestamp and the number of microseconds. * PHP function microtime () syntax * microtime (get_as_float) * PHP function microtime () parameter and description * get_as_float if the get_as_float parameter is given and its value is equivalent to TRUE, this function returns a floating point number. * In layman's terms, true indicates that only one floating point number (that is, the number of seconds) is returned, and a string in microsecond + second is returned without the parameter. *
"; * Echo microtime (true); *?> * The result is as follows: * 0.00000600 1283757623*1283757623 */$ uniName = md5 (uniqid (microtime (true), true )). '. '. $ ext; // $ destination = $ path. '/'. $ fileInfo ['name']; $ destination = $ path. '/'. $ uniName; if (@ move_uploaded_file ($ fileInfo ['tmp _ name'], $ destination) {echo 'file uploaded successfully ';} else {echo 'file Upload failed';} else {// Match error message switch ($ fileInfo ['error']) {case 1: echo 'The uploaded file exceeds the value of the upload_max_filesize option in the PHP configuration file '; break; case 2: echo' exceeds the size limit of the form MAX_FILE_SIZE '; break; case 3: echo 'file partially upload'; break; case 4: echo 'file not selected to be uploaded '; break; case 6: echo 'temporary directory not found'; break; case 7: case 8: echo 'system error'; break ;}}
The above introduces the implementation and introduction of PHP file upload, including PHP files and file upload content, and hopes to help friends who are interested in PHP tutorials.