Php+ajax implementation with progress bar upload picture function "with demo source download" _php Tips

Source: Internet
Author: User

The example of this article describes the Php+ajax implementation with progress bar upload picture function. Share to everyone for your reference, specific as follows:

The Operation effect chart is as follows:

The code is as follows:

<?php if (isset ($_files["FileInput"]) && $_files["FileInput" ["Error"]== upload_err_ok) {############ Edit Settings ############## $UploadDirectory = ' f:/websites/file_upload/uploads/'; Specify upload directory ends with/(slash) ##########################################/* Note:you'll run int
  o Errors or blank page if "Memory_limit" or "upload_max_filesize" is set to low in "php.ini". Open "php.ini" file, and search for "memory_limit" or "upload_max_filesize" limit and set them adequately, also check "p
  Ost_max_size ".
  * *//check If this is a AJAX request if (!isset ($_server[' Http_x_requested_with ')) {die ();
  //is file size is less than allowed size.
  if ($_files["FileInput"] ["size"] > 5242880) {die ("File size is too big!"); //allowed file type Server side check switch (strtolower ($_files[' FileInput ' [' type '])) {//allowed file Ty
     PES case ' image/png ': Case ' image/gif ': Case ' image/jpeg ': Case ' image/pjpeg ': Case ' text/plain ': Case ' text/html '://html file Case ' application/x-zip-compressed ': Case ' application/pdf ': Case ' application/msword ': Case ' application/vnd.ms-excel ': Case ' video
      /mp4 ': break; Default:die (' Unsupported file! ');
  Output error} $File _name = Strtolower ($_files[' FileInput '] [' Name ']); $File _ext = substr ($File _name, Strrpos ($File _name, '. ')); Get file extention $Random _number = rand (0, 9999999999);
  Random number to is added to name. $NewFileName = $Random _number. $File _ext; New file name if (Move_uploaded_file ($_files[' FileInput '] [' tmp_name '], $UploadDirectory. $NewFileName)) {die (' success!
  File uploaded. ');
  }else{die (' Error uploading file! '); } else {die (' something wrong with upload!
Is "upload_max_filesize" set correctly? ');

 }

Full instance code click here to download the site.

More interested in PHP related content readers can view the site topics: "PHP file Operation Summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", "Basic PHP Grammar Introduction Tutorial", "PHP operation Office Document skills Summary (including Word, Excel,access,ppt), "The PHP date and time usage summary", "PHP object-oriented Programming Introduction Tutorial", "PHP string (String) Usage Summary", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation skill Summary"

I hope this article will help you with the PHP program design.

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.