开发者

CakePHP: MeioUpload Behavior

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 th开发者_如何学编程e $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???


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'),
    ...


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜