CakePHP:MeioUpload行为

时间:2010-07-14 13:06:21

标签: cakephp behavior

我想使用[MeioUpload Behavior] [1]上传PDF,DOC,XLS等文档但我收到文件类型无效错误。

我的上传模型如下所示:

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'),
         )
     )
 );
}

当我在MeioUpload类中调试 $ defaultOptions $ options ['allowedMime'] 时...它使用默认的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
)

为什么行为不使用我声明的allowed_mime ???

我知道如何覆盖默认的allowed_mime ???

2 个答案:

答案 0 :(得分:2)

在上传模型中,您需要在camelCase中编写选项:

   ... 
    'allowedMime' => array('application/pdf', 'application/msword', 'application/mspowerpoint', 'application/excel', 'application/rtf', 'application/zip'),
'allowedExt' => array('.pdf', '.doc', '.ppt', '.xls', '.rtf', '.zip'),
    ...

答案 1 :(得分:-1)

对于图像上传,您可以使用图像行为来控制图像上传... 我认为此链接有助于了解有关cakephp图像行为的更多信息............

http://cakephplogics.blogspot.in/2014/07/cakephp-image-upload-behavior.html