Ajax asynchronous Upload Based on the bootstrap upload plug-in fileinput (supports multi-File Upload preview and drag/drop), fileinputajax

Source: Internet
Author: User

Ajax asynchronous Upload Based on the bootstrap upload plug-in fileinput (supports multi-File Upload preview and drag/drop), fileinputajax

First, you need to import some js and css files.

<Link href = "_ PUBLIC _/CSS/bootstrap.css" rel = "external nofollow" rel = "stylesheet"> <link type = "text/css" rel = "stylesheet "href =" _ PUBLIC _/CSS/fileinput.css "rel =" external nofollow "/> <script type =" text/javascript "src =" _ PUBLIC __/ JS/bootstrap. min. js "> </script> <script type =" text/javascript "src =" _ PUBLIC _/JS/jquery. min. js "> </script> <script type =" text/javascript "src =" _ PUBLIC _/JS/fileinput. js "> </script> <script type =" text/javascript "src =" _ PUBLIC _/JS/fileinput_locale_zh.js "> </script>/Chinese package, no need to import

Html code

<form enctype="multipart/form-data">  <input id="file-1" name="file" type="file" multiple class="file" data-overwrite-initial="false" data-min-file-count="1"/></form>

Js Code

$ ("# File-1 "). fileinput ({uploadUrl: '', // you must set a path to enter the php code section allowedFileExtensions: ['jpg ', 'png', 'gif', 'txt ', 'zip', 'ico ', 'jpeg', 'js', 'css ', 'java', 'mp3', 'mp4', 'Doc ', 'docx'], // allowed file types overwriteInitial: false, maxFileSize: 1500, // The maximum file size unit is k maxFilesNum: 10, // maximum number of files // allowedFileTypes: ['image', 'video', 'flash'], slugCallback: function (filename) {return filename ;}});

Php code

$ File = $ _ FILES ['file']; // obtain the information of the object named above, array format $ date ['file _ name'] = $ file ['name']; // file name $ date ['file _ size'] = $ file ['SIZE']; // file size $ date ['file _ type'] = $ file ['type']; // file type

Then upload and use ajax to return an error message or success message.

It can also be returned directly using echo.

Style:

The above section describes the ajax asynchronous upload function of the bootstrap-based upload plug-in fileinput (supporting multi-File Upload preview and drag-and-drop), which is helpful to you, if you have any questions, please leave a message and the editor will reply to you in time. Thank you very much for your support for the help House website!

Related Article

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.