【问题标题】:Cakephp image -Can not determine the mimetypeCakephp 图像 - 无法确定 mimetype
【发布时间】:2014-01-13 05:49:02
【问题描述】:

cakephp 2.3

我正在上传图片,但出现错误提示:

Can not determine the mimetype.

Error: An Internal Error Has Occurred.

在我的模型上,这是我的 $validation 的一部分

'file_name' => array(
            'uploadError' => array(
                'rule' =>'uploadError',
                'message' => 'Your image upload failed',
                'allowEmpty' => FALSE,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
            'mimeType' => array(
                'rule' => array('mimeType', array('image/gif', 'image/png', 'image/jpg', 'image/jpeg')),
                'message' => 'Please only upload images (gif, png, jpg).',
                'allowEmpty' => FALSE,
                ),
            'fileSize' => array(
                'rule' => array('fileSize', '<=', '2MB'),
                'message' => 'Your image must be less than 2MB or(2048ko).',
                'allowEmpty' => FALSE,
                ),
            'processCoverUpload' => array(
                'rule' => 'processCoverUpload',
                'message' => 'Unable to process cover image upload.',
                'allowEmpty' => FALSE,
                ),
            'unique' => array(
                'rule' => 'isUnique',
                'message' => 'This file name is already exist in your folder',
                'required' => 'create',
                'allowEmpty' => FALSE,
                ),
        ),

我只允许使用 3 种类型的 mimetype。有什么帮助吗?

【问题讨论】:

  • PHP 版本?您是否将表单设置为输入file
  • 感谢蒂格兰。是的,我有 code Form->create('Image', array('type' => 'file')); ?> .....echo $this->Form->input('file_name', array('type' => 'file')); ...PHP 5.3 版
  • 您是否将调试设置为 2?除了内部错误消息吗?
  • 是的,我确实将它设置为 2。我有一个内部错误(我发布的那个),另一个是堆栈跟踪...
  • 您的服务器上有fileinfo 扩展吗?如果不是,它使用已弃用的mime_content_type,所以它可能不那么聪明......

标签: cakephp cakephp-2.0 cakephp-2.3


【解决方案1】:

我刚刚遇到了完全相同的问题。感谢其他一些为我指明正确方向的 cmets,这是我的解决方案: 编辑 php.ini(Win7 上为 \xampp\php\php.ini)搜索 extension=php_fileinfo.dll 并取消注释。

仅供参考:我正在运行 xampp 1.7.7 [Apache:2.2.21; PHP:5.3.8; MySQL:5.5.16]。希望在较新的 xampp 版本上默认启用扩展。

【讨论】:

  • 我认为您需要在更改后重新启动xampp,然后问题才能解决
猜你喜欢
  • 2014-04-09
  • 2016-06-08
  • 1970-01-01
  • 1970-01-01
  • 2013-12-23
  • 2015-07-24
  • 1970-01-01
  • 1970-01-01
  • 2014-10-01
相关资源
最近更新 更多