admin管理员组

文章数量:1295257

I'm using blueimp File Upload plugin to upload files. There's an example regex to restrict the upload to images only:

var acceptFileTypes = /^image\/(gif|jpe?g|png)$/i;

How can I change this to upload image files, and documents like PDF, TXT, DOC?

I'm using blueimp File Upload plugin to upload files. There's an example regex to restrict the upload to images only:

var acceptFileTypes = /^image\/(gif|jpe?g|png)$/i;

How can I change this to upload image files, and documents like PDF, TXT, DOC?

Share Improve this question asked Apr 7, 2014 at 18:53 user1049961user1049961 2,7369 gold badges40 silver badges69 bronze badges 1
  • 3 Is it not working now? If so, what errors/unexpected results? If it is working and you just want to add extensions, just add it to the group of ORs ([..]png|pdf|txt|doc)$). – Sam Commented Apr 7, 2014 at 18:55
Add a ment  | 

2 Answers 2

Reset to default 9
var acceptFileTypes =
/^image\/(gif|jpe?g|png)$|^application\/(pdf|msword)$|^text\/plain$/i;

This seems to assume that the correct mime type is checked against acceptFileTypes

var acceptFileTypes = /^image\/(gif|jpe?g|png|pdf|doc|txt)$/i;

and make sure that these files are kept inside the image folder. so the full path to the text file should be something like /image/dsds/file.txt

if you want to add your own folder name it accordingly

本文标签: Javascriptregex to validate document filesPDFtxtdocStack Overflow