3

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?

1

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.