file-> getMimeType()总是返回Zend Framework的应用程序/八位字节流 [英] file->getMimeType() always returns application/octet-stream with Zend Framework

查看:179
本文介绍了file-> getMimeType()总是返回Zend Framework的应用程序/八位字节流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  $ this-> archivo = new Zend_Form_Element_File('archivo');我的文件表单元素非常简单: 
$ this-> archivo-> setLabel('Archivo:')
- > setRequired(true)
- > setDestination(UPLOAD_PATH)
- > addValidator ('Count',false,1)
- > addValidator('Size',false,MAX_FILE_SIZE)
- > addValidator('Extension',false,Application_Form_Multimedia_SubirArchivo :: EXTENSIONES_PERMITIDAS);
$ this-> addElement($ this-> archivo);

但是,当上传文件时(上传OK),我尝试获取MIME类型文件是相同的:

  $ form-> archivo-> getMimeType()


为什么会发生这种情况呢,我错过了什么?谢谢
解决方案

最可能的原因是,如果您的PHP安装中既没有fileinfo或mime_magic扩展,底层您使用的方法将回退到默认的mimetype:

  if(empty($ result [$ key])){
$ result [$ key] ='application / octet-stream';



$ b建议您检查Zend_File_Transfer_Adapter_Abstract中的getMimeType()方法 - 代码片段的来源并从Zend_Form_Element_File :: getMimeType()中调用 - 详细信息,然后检查你已经安装了什么扩展,并适当纠正。


my file form element is very simple:

$this->archivo = new Zend_Form_Element_File('archivo');
$this->archivo->setLabel('Archivo:')
        ->setRequired(true)
        ->setDestination(UPLOAD_PATH)
        ->addValidator('Count', false, 1)
        ->addValidator('Size', false, MAX_FILE_SIZE)
        ->addValidator('Extension', false, Application_Form_Multimedia_SubirArchivo::EXTENSIONES_PERMITIDAS);
$this->addElement($this->archivo);

but, when uploading the file (uploads OK), I try to obtain the MIME type but for every file is the same:

$form->archivo->getMimeType()

It always returns application/octet-stream, no matter what kind of file I'm trying to upload.

Why is this happening, did I miss something in the way? Thanks

解决方案

The most likely reason for this is that if neither the fileinfo or mime_magic extensions are available in your PHP installation, the underlying method you're using will fallback to a default mimetype:

if (empty($result[$key])) {
    $result[$key] = 'application/octet-stream';
}

Suggest you check the getMimeType() method within Zend_File_Transfer_Adapter_Abstract - where that snippet is from and called from within Zend_Form_Element_File::getMimeType() - for details, and then check what extensions you have installed and rectify appropriately.

这篇关于file-> getMimeType()总是返回Zend Framework的应用程序/八位字节流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆