Features of PHP download

Source: Internet
Author: User
This article introduces the content is about the PHP download function, has a certain reference value, now share to everyone, the need for friends can refer to

upload.php start

<?phpfunction upload_file ($fileInfo, $uploadPath = './uploads ', $imageFlag =true, $allowExt =array (' jpeg ', ' jpg ', ' PNG ', ' gif '), $maxSize =209708) {define (' Upload_errs '), [' upload_max_filesize ' = ' + ' exceeded the PHP config file upload_max_ The value of the FileSize option ', ' form_max_size ' = ' + ' exceeds the value of the form max_file_size option ', ' upload_file_partial ' = ' file part is uploaded ', ' No_upload_file _select ' + ' does not have the option to upload the file ', ' upload_system_error ' = ' system error ', ' no_allow_ext ' = ' illegal file type ', ' exceed_max_size ' = ' + ' exceeded Maximum allowed uploads ', ' not_true_image ' = ' = ' file is not a real image ', ' not_http_post ' + ' file is not uploaded via HTTP post ', ' move_error ' \ = ' File move lost ($fileInfo [' Error ']===upload_err_ok) {//Detect upload file type $ext =strtolower (pathinfo ($fileInfo [' name '],    pathinfo_extension));      if (!in_array ($ext, $allowExt)) {echo upload_errs[' no_allow_ext '];    return false;      }//detects if the upload file size conforms to the specification if ($fileInfo [' Size ']> $maxSize) {echo upload_errs[' exceed_max_size '];    return false; }//Detect if the true picture if ($imageFlag) {if (@!getimagesize ($fileInfo [' Tmp_name ']) {echo upload_errs[' not_true_image '];      return false; }}//detect if the file is uploaded via HTTP post (!is_uploaded_file ($fileInfo [' Tmp_name '])} {return upload_errs[' Not_http_po    St '];    }//detects if the target directory exists, does not exist then creates if (!is_dir ($uploadPath)) {mkdir ($uploadPath, 0777,true); }//Generate unique file names to prevent overwriting of duplicate names $uniName =md5 (Uniqid (Microtime (True), true)).    $ext;    $dest = $uploadPath. Directory_separator. $uniName;      Move the file if (@!move_uploaded_file ($fileInfo [' Tmp_name '], $dest)) {echo upload_errs[' move_error '];    return false;    } echo ' file upload succeeded ';  return $dest;      }else{switch ($fileInfo [' ERROR ']) {Case 1://$mes = ' exceeds the value of the upload_max_filesize option in the PHP configuration file ';      $mes =upload_errs[' upload_max_filesize '];      Break      Case 2: $mes =upload_errs[' form_max_size ');      Break      Case 3: $mes =uplaod_errs[' upload_file_partial ');      Break      Case 4: $mes =upload_errs[' no_upload_file_select ');      Break      Case 6:Case 7:case 8: $mes =uplaod_errs[' Upload_system_error '];    Break    } Echo $mes;  return false; }}?>

Upload.php End

The beginning of HTML <! DOCTYPE html>

The end of the doupload.php

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.