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?

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top