问题
I would like to use the [MeioUpload Behavior][1] for uploading documents like PDF, DOC, XLS etc. but I get an Invalid file type error.
My Upload Model looks like this:
class Upload extends AppModel {
var $name = 'Upload';
var $actsAs = array(
'MeioUpload.MeioUpload' => array(
'upload_file' => array(
'dir' => 'files{DS}uploads',
'create_directory' => true,
'allowed_mime' => array('application/pdf', 'application/msword', 'application/mspowerpoint', 'application/excel', 'application/rtf', 'application/zip'),
'allowed_ext' => array('.pdf', '.doc', '.ppt', '.xls', '.rtf', '.zip'),
)
)
);
}
When I debug the $defaultOptions $options['allowedMime'] in the MeioUpload class... it's uses the default allowedMime:
Array
(
[0] => image/jpeg
[1] => image/pjpeg
[2] => image/png
[3] => image/gif
[4] => image/bmp
[5] => image/x-icon
[6] => image/vnd.microsoft.icon
)
Why is the Behavior not using my declared allowed_mime ???
Any idea how I can overwrite the default allowed_mime???
回答1:
In the Upload Model you need to write the options in camelCase:
...
'allowedMime' => array('application/pdf', 'application/msword', 'application/mspowerpoint', 'application/excel', 'application/rtf', 'application/zip'),
'allowedExt' => array('.pdf', '.doc', '.ppt', '.xls', '.rtf', '.zip'),
...
回答2:
For image uploading you can use image behavior to control image uploading... i think this link is useful for learn more about cakephp image behavior...........
http://cakephplogics.blogspot.in/2014/07/cakephp-image-upload-behavior.html
来源:https://stackoverflow.com/questions/3246376/cakephp-meioupload-behavior