Support multi-file upload, preview, drag-and-drop, Bootstra-based upload plugin fileinput ajax asynchronous upload

Source: Internet
Author: User

First you need to import some JS and CSS files

<link href= "__public__/css/bootstrap.css" rel= "stylesheet" >

<link type= "Text/css" rel= "stylesheet" href= "__public__/css/fileinput.css"/>

<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 pack, 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: ',//must set a path into the PHP code section
Allowedfileextensions: [' jpg ', ' png ', ' gif ', ' txt ', ' zip ', ' ico ', ' jpeg ', ' js ', ' CSS ', ' java ', ' mp3 ', ' mp4 ', ' Doc ', ' docx ', Types of files Allowed
Overwriteinitial:false,
The maximum size of the maxfilesize:1500,//file is K
maxfilesnum:10,//Maximum number of files
Allowedfiletypes: [' Image ', ' video ', ' Flash '],
Slugcallback:function (filename) {
return filename;
}
});

PHP code

$file =$_files[' file '];//gets the information on the file that is called the array form

$date [' file_name '] = $file the name of the [' Name '];//file
$date [' file_size '] = $file the size of the [' ' Size '];//file
$date [' file_type '] = $file the type of the [' ' Type '];//file

Then upload and return an error message or success message with Ajax

Returning directly with Echo is also OK.

Style:

Support multi-file upload, preview, drag-and-drop, Bootstra-based upload plugin fileinput ajax asynchronous upload

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.