CakePHP: MeioUpload Behavior

♀尐吖头ヾ 提交于 2019-12-13 03:39:40

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!