Phpjquery multi-file Upload implementation code

Source: Internet
Author: User
Phpjquery multi-file Upload implementation code

  1. Upload

  2. Script
  3. $ (Document). ready (function ()
  4. {
  5. Var settings = {
  6. Url: "upload. php ",
  7. Method: "POST ",
  8. AllowedTypes: "jpg, png, gif, doc, pdf, zip ",
  9. FileName: "myfile ",
  10. Multiple: true,
  11. OnSuccess: function (files, data, xhr)
  12. {
  13. $ ("# Status" 2.16.html ("Upload is success ");

  14. },

  15. OnError: function (files, status, errMsg)
  16. {
  17. $ ("# Status" 2.16.html ("Upload is Failed ");
  18. }
  19. }
  20. $ ("# Mulitplefileuploader"). uploadFile (settings );

  21. });

  22. Script

2. php multi-file upload code upload. php

  1. // If directory doesnot exists create it.

  2. $ Output_dir = "../upload ";

  3. If (isset ($ _ FILES ["myfile"])

  4. {
  5. $ Ret = array ();
  6. $ Error = $ _ FILES ["myfile"] ["error"];
  7. {
  8. If (! Is_array ($ _ FILES ["myfile"] ['name']) // single file
  9. {
  10. $ FileName = $ _ FILES ["myfile"] ["name"];
  11. Move_uploaded_file ($ _ FILES ["myfile"] ["tmp_name"], $ output_dir. $ _ FILES ["myfile"] ["name"]);
  12. // Echo"
    Error: ". $ _ FILES [" myfile "] [" error "];
  13. $ Ret [$ fileName] = $ output_dir. $ fileName;
  14. }
  15. Else
  16. {
  17. $ FileCount = count ($ _ FILES ["myfile"] ['name']);
  18. For ($ I = 0; $ I <$ fileCount; $ I ++)
  19. {
  20. $ FileName = $ _ FILES ["myfile"] ["name"] [$ I];
  21. $ Ret [$ fileName] = $ output_dir. $ fileName;
  22. Move_uploaded_file ($ _ FILES ["myfile"] ["tmp_name"] [$ I], $ output_dir. $ fileName );
  23. }
  24. }
  25. }
  26. Echo json_encode ($ ret );
  27. }
  28. ?>

3, as follows:

>>> Articles you may be interested in: PHP image uploads (multifile uploads, thumbnails, and watermarks) PHP example code for uploading multiple files and multiple images php simple example for uploading multiple files analysis example for uploading php common forms multiple files php multifile Upload simple example (getting started) php multi-file upload methods

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.