PHP file upload implementation and its introduction PHP file is what file php upload file code php file upload size set

Source: Internet
Author: User
Tags php file upload
about implementation and introduction in the program notes.

File Submission page: (can be submitted separately to doaction.php, doaction1.php, doaction2.php for testing)

upload.php

    
 
      File Upload    

doaction.php

 
doaction1.php

  
doaction2.php

    $maxSize) {exit (' upload file too large '); } echo $fileInfo [' type '];    Exit    $ext = Strtolower (End (Explode ('. '), $fileInfo [' name ']));    $ext = PathInfo ($fileInfo [' name '],pathinfo_extension);    if (!in_array ($ext, $allowExt)) {exit (' illegal file type ');    }//Determine if the file was sent via HTTP post (!is_uploaded_file ($fileInfo [' tmp_name '])) {exit (' file is not transmitted via HTTP POST) '; }//detection is true for picture type//* * getimagesize ($FILENAME): Gets the information of the specified picture, if it is a picture return array * If it is not a picture (even if the file suffix is the format of the picture, actually not the picture), return Fals     E.        */if ($flag) {if (!getimagesize ($fileInfo [' tmp_name '])) {exit (' not a true picture type ');    }} $path = ' uploads ';     PHP uses mkdir to create multilevel directories http://www.daixiaorui.com/read/38.html/* * mkdir ($path, 0777,true);     * First parameter: must, represents the path of the multilevel directory to be created; * Second parameter: Set directory permissions, default is 0777, meaning the maximum possible access; * Third parameter: True to allow the creation of multilevel catalogs.     */* * * chmod () function changes file mode.     * Returns TRUE if successful, otherwise FALSE. */if (!file_exists ($path)) {mkdir ($path, 0777, true);//0777 indicates a readable writable executable chMoD ($path, 0777);     }//Make sure the file name is shifted, place duplicate names to produce overrides/* * the UNIQID () function generates a unique ID based on the current time in microseconds. * Syntax * UNIQID (prefix,more_entropy) * parameter description * Prefix optional. Specify a prefix for the ID.     This parameter is useful if two scripts generate IDs exactly in the same microsecond. * More_entropy Optional.     Specifies more entropy at the end of the return value.     */* * MICROTIME () returns the current Unix timestamp and 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, the function returns a floating-point number.     * Popularly speaking, with parameter True indicates that only one floating-point number (that is, seconds) is returned, with no parameters returning a microsecond + second string.  *
   ";     * Echo Microtime (TRUE);  *?> * results are 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 upload succeeded ';    } else {echo ' file upload failed '; }} else {//Match error message switch ($fileInfo [' ERROR ']) {case 1:echo ' upload file exceeds upload_max_filesize option in PHP config file            Value of ';        Break            Case 2:echo ' exceeds the size of the form max_file_size limit ';        Break            Case 3:echo ' file part was uploaded ';        Break            Case 4:echo ' no option to upload file ';        Break            Case 6:echo ' No temporary directory found ';        Break            Case 7:case 8:echo ' system error ';    Break }}

The above introduces the implementation of PHP file upload and its introduction, including PHP files, file Upload aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

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