Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

file input throws an error when form is submitted

Tags:

html

php

I run into a problem when trying to upload images to the server using a symfony form as follows:

$form = $this->createFormBuilder($image)
    ->add('full', FileType::class, array('label' => 'Imagen', 'multiple' => true))
    ->add('save', SubmitType::class, array('label' => 'Guardar'))
    ->getForm();

Then in the html:

{{ form_start(form) }}                        
{{ form_row(form.full) }}
{{ form_end(form)  }}

When I inspect the html I get:

<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>

When I get the value of the file in the controller I have this:

originalName="myPicture.jpg"
mimeType="image/jpeg"
size=8450
erro=0
*SplFileInfo*pathName="E:\xamp\tmp\php51B5.tmp"
*SplFileInfo*fileName="php51B5.tmp"

So far, well, but in other cases of other images with the same format (jpeg), it happens that I get this:

originalName="myPicture.jpg"
mimeType="application/octet-stream"
size=0
erro=1
*SplFileInfo*pathName=""
*SplFileInfo*fileName=""

As you can see it does not recognize the Mimetype that should be image / jpeg, and it shows that an error occurs but it does not say which one?

like image 545
Armando Rodríguez Acosta Avatar asked Mar 24 '26 13:03

Armando Rodríguez Acosta


1 Answers

As RiggsFolly said, the problem is that the error = 1 means that the file you are trying to upload is larger than the limit set in the php.ini of the server, changing this parameter is solved:

php.ini:

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize=8M
like image 76
Armando Rodríguez Acosta Avatar answered Mar 27 '26 02:03

Armando Rodríguez Acosta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!