使用 Zend Form 上传图像无法确定图像扩展名
我无法确定使用 Zend Framework 上传的图像的文件类型。 每次我尝试使用 $_FILES['File']['type'] 确定文件类型时,我总是得到applicationoctet-stream。只有在检查表单是否已发布之前确定类型时,我才能获得正确的扩展名。有谁知道为什么?有更好的方法来处理这个问题吗?
这有效:
$form = new Form_Reg;
$this->view->Reg = $form;
if(isset($_FILES['File']['type'])){
$filetype = $file = $_FILES['File']['type'];
}
if ($this->getRequest()->isPost()){
$formData = $this->_request->getPost();
if($form->isValid($formData)){
echo $filetype;
exit;
}
}
这不起作用:
$form = new Form_Reg;
$this->view->Reg = $form;
if ($this->getRequest()->isPost()){
$formData = $this->_request->getPost();
if($form->isValid($formData)){
$filetype = $file = $_FILES['File']['type'];
echo $filetype;
exit;
}
}
I'm having trouble determining the file-type of an image I uploaded with Zend Framework.
Everytime I try to determine the filetype with $_FILES['File']['type'], I always get applicationoctet-stream. Only when I determine the type before checking if the form is posted do I get the right extension. Does anyone know why? Is there a nicer way of dealing with this?
this works:
$form = new Form_Reg;
$this->view->Reg = $form;
if(isset($_FILES['File']['type'])){
$filetype = $file = $_FILES['File']['type'];
}
if ($this->getRequest()->isPost()){
$formData = $this->_request->getPost();
if($form->isValid($formData)){
echo $filetype;
exit;
}
}
This doesn't work:
$form = new Form_Reg;
$this->view->Reg = $form;
if ($this->getRequest()->isPost()){
$formData = $this->_request->getPost();
if($form->isValid($formData)){
$filetype = $file = $_FILES['File']['type'];
echo $filetype;
exit;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在 stackoverflow 上看到了更多有关此问题的问题,但找不到解决我的特定问题的答案。问题是 zend form 无法验证上传的文件是否是图像,一旦它开始处理表单,文件类型就会变成 applicationoctet-stream,无论上传什么类型的文件。
诀窍是调整 php.ini,查找并取消注释:extension=php_fileinfo.dll。
我仍然想知道 zend_form 需要 fileinfo 做什么, $_FILES 全局在没有 fileinfo 的情况下工作。
I've seen more questions about this on stackoverflow but couldn't find the answer that solved my particular problem. The problem was that zend form couldn't validate if the uploaded file was an image, as soon as it started processing the form the filetype would change into applicationoctet-stream, no mather what kind of file was uploaded.
The trick was to adjust the php.ini, look for this and uncomment it: extension=php_fileinfo.dll.
Still I wonder what zend_form does that fileinfo is needed, the $_FILES global works without fileinfo.