无法上传带有 MIME 类型“应用程序/八位字节流"的图像;在 Symfony2 [英] Can't upload image with mime-type "application/octet-stream" in Symfony2
问题描述
让我说说这个问题.我有一个叫做图像"的表格.它包含一个名为 «file» 的字段,它被检查为图像实现.这是validation.yml的一部分:
Let me tell about the problem. I have a form which is called «Image». It contains a field called «file» and it is checked as Image implementation. Here is a part of validation.yml:
noxaeterna\MainBundle\Model\Image:
constraints:
- Propel\PropelBundle\Validator\Constraints\UniqueObject:
fields: hash
message: "Такое изображение уже существует."
properties:
name:
- NotBlank:
message: "Имя изображения не задано."
- Length:
max: 255
maxMessage: "Длина названия не должна превышать {{ limit }} символов."
file:
- NotBlank:
message: "Изображение не загружено"
- Image:
maxSize: 20M
mimeTypes: ["image/jpeg", "image/gif", "image/png", "image/x-png", "image/x-citrix-png", "image/x-citrix-jpeg", "image/pjpeg"]
minWidth: 1
minHeight: 1
minWidthMessage: "Изображение должно быть не менее {{ limit }} пикселей в ширину."
minHeightMessage: "Изображение должно быть не менее {{ limit }} пикселей в высоту."
sizeNotDetectedMessage: "Недопустимый формат изображения: не удалось определить размеры."
mimeTypesMessage: "Недопустимый формат изображения."
maxSizeMessage: "Файл слишком большой ({{ size }} байт). Размер не должен превышать {{ limit }}."
uploadIniSizeErrorMessage: "Файл слишком большой ({{ size }} байт). Размер не должен превышать {{ limit }}."
uploadFormSizeErrorMessage: "Файл слишком большой ({{ size }} байт). Размер не должен превышать {{ limit }}."
uploadErrorMessage: "Ошибка загрузки изображения."
那么问题出在哪里?当我尝试上传一些具有 MIME 类型 «application/octet-stream» 并具有正常扩展名(如 .jpg 或 .png)的图像时,我看到一个错误,告诉我图像的大小无效.然后我尝试通过 var_dump() 显示 «Image» 的对象(一个实现),我看到 «size» 字段为 0(这就是显示无效大小错误的原因).
So what is the problem? When I try to upload some images which have mime-type «application/octet-stream» and have normal extension like .jpg or .png I see an error which tells me that an image has invalid size. Then I try to display the object (an implementation) of «Image» through var_dump() and I see that the «size» field is 0 (it's why the error of invalid size is displayed).
那么我对这些图像做了什么来确定它们的大小并成功下载它们(我必须说,使用一种允许的 mime 类型它效果很好)?
So what I have do with such images to determine their size and download them successfully (I must say that with one of allowed mime-type it works pretty good)?
附言我很抱歉我的英语不好.和以往一样,我将感谢您的任何答复!
P.S. I'm sorry about my bad English skill. And as ever I will be thankfull for any answer!
有新信息!.所有大于几兆字节的文件都以 «application/octet-stream» mime 类型发送.
There is new information!. All files which bigger than several megabytes are sent with «application/octet-stream» mime-type.
推荐答案
我添加了我的评论,它解决了它作为答案,所以问题会有答案:
有新信息!.所有大于几兆字节的文件都以 «application/octet-stream» mime 类型发送.
There is new information!. All files which bigger than several megabytes are sent with «application/octet-stream» mime-type.
问题是 php.ini 中的 post_max_size 或 upload_max_filesize 限制了上传的大小.
The problem is that either post_max_size or upload_max_filesize in your php.ini is limiting the size of the upload.
这篇关于无法上传带有 MIME 类型“应用程序/八位字节流"的图像;在 Symfony2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!