尝试使用symfony表单将图像上传到服务器时遇到问题,如下所示:
$form = $this->createFormBuilder($image)
->add('full', FileType::class, array('label' => 'Imagen', 'multiple' => true))
->add('save', SubmitType::class, array('label' => 'Guardar'))
->getForm();
然后在html中输入
:{{ form_start(form) }}
{{ form_row(form.full) }}
{{ form_end(form) }}
当我检查html时,我得到:
<form name="form" method="post" enctype="multipart/form-data">
<div class="form-group">
<label class="control-label required" for="form_full">Imagen</label>
<input type="file" id="form_full" name="form[full][]" required="required" multiple="multiple" />
</div>
<div class="form-group">
<button type="submit" id="form_save" name="form[save]" class="btn-default btn">Guardar</button>
</div>
<input type="hidden" id="form__token" name="form[_token]" value="vZjUzyZCsbsx5TmfWiljncIi1pPymfod_jezOOKgK_k" />
</form>
当我在控制器中获得文件的值时,我得到了:
originalName="myPicture.jpg"
mimeType="image/jpeg"
size=8450
erro=0
*SplFileInfo*pathName="E:\xamp\tmp\php51B5.tmp"
*SplFileInfo*fileName="php51B5.tmp"
到目前为止,很好,但是在其他具有相同格式(jpeg)的图像的其他情况下,碰巧我得到了:
originalName="myPicture.jpg"
mimeType="application/octet-stream"
size=0
erro=1
*SplFileInfo*pathName=""
*SplFileInfo*fileName=""
如您所见,它无法识别应为image / jpeg的Mimetype,并且表明发生了错误,但未说明是哪一个?
答案 0 :(得分:1)
正如RiggsFolly所说,问题在于error = 1
意味着您试图上传的文件大于服务器php.ini
中设置的限制,解决了更改此参数的问题:< / p>
php.ini:
; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize=8M