开发者

Zend Framework Can't determine mime type of image upload

开发者 https://www.devze.com 2023-03-03 09:51 出处:网络
Hi all I\'m trying to upload a image when creating a item in my app, however the action fails returning the following error: The mimetype of file \'mytestimage.jpg\' could not be detected.

Hi all I'm trying to upload a image when creating a item in my app, however the action fails returning the following error: The mimetype of file 'mytestimage.jpg' could not be detected. I've tried adding a Mime Type validator but the error persists, can anyone tell me where I'm going wrong in the code below.

// Image uploads
$images = new Zend_Form_Element_File('images');开发者_Python百科
$images->setMultiFile(2)
       ->addValidator('IsImage')
       ->addValidator('Size',false,'5242880')
       ->addValidator('Extension',false,'jpg,png,gif')
       ->addValidator('ImageSize',false,array(
                 'minwidth' => 250,
                 'minheight'=>250,
                 'maxwidth'=>500,
                 'maxheight'=>500
                 ))
       ->setValueDisabled(true);

Many thanks in advance.

Graham


I had the same problem.

Zend_Frameworks tries to determine the mimetype in two ways:

  • First it tries to use the PECL FILEINFO-Extension (which is not installed on every server)
  • if the extension is not istalled it tries to use mime_content_type (a php function). This function however is deprecated as of php version 5.3

So in this case I guess your hoster is using php version 5.3 and has not installed the PECL FILEINFO-Extension. Same goes unfortunately for my hoster :(

Here are more details of the two ways in the php-manual:

  • http://de.php.net/manual/en/function.mime-content-type.php
  • http://de.php.net/manual/en/ref.fileinfo.php

By the way. You can see the code ZF uses in the file "Zend\File\Transfer\Adapter\Http.php" (lines 1281-1318: methodname is _detectMimeType

0

精彩评论

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