我有一个文件上传功能,我想允许图像和文档并禁止其他文件,只检查扩展名听起来是个坏主意。
我拥有的代码片段是:
var $actsAs = array(
'MeioUpload' => array(
'file' => array(
'dir' => 'uploads{DS}{ModelName}',
'fields' => array(
'filesize' => 'size',
'mimetype' => array('image/jpeg', 'image/pjpeg', 'image/gif',
'image/png', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.openxmlformats-officedocument.presentationml.presentation','application/pdf'),
'message' => 'Please upload a valid document file'
),
'allowed_mime' => array('image/jpeg', 'image/pjpeg', 'image/gif',
'image/png', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.openxmlformats-officedocument.presentationml.presentation','application/pdf'),
'allowed_ext' => array(' .docx',' .jpg',' .jpeg',' .png',' .gif',' .doc',' .xls',' .xlsx',' .pdf'),
'validations' => array(
'MaxSize' => array(
'check' => false,
),
),
'message' => 'Invalid File. Please upload only document or images'
),
),
);
如何分配 mimetypes 以允许:.txt、.doc、.docx、.xls、.xlsx、.pdf、.png、.jpg、.gif、.jpeg
MEIOUPLOAD 调整会很棒!