Avoiding exceptions when uploading files in laravel

Posted by occam98 on Stack Overflow See other posts from Stack Overflow or by occam98
Published on 2012-06-21T20:23:59Z Indexed on 2012/11/01 11:01 UTC
Read the original article Hit count: 337

Filed under:

I've got a file upload field (attachment1) in a form that may or may not have a file uploaded in it when I process the form in laravel.

When I'm trying to process the page, this line generates an exception:

Input::upload('attachment1',path('storage').'attachments/'.$name);

Here is the text of the exception:

Message: Call to a member function move() on a non-object

it seems that I need to check in advance to see if 'attachment1' has a file, and I found that the function Input::has_file('attachment1') is supposed to tell me whether or not 'attachment1' has a file, but even when I submit an empty form, it returns true.

Also, from reading documentation, it seems that Input::upload is supposed to just return false when trying to upload a non-existant file, so why does it produce this exception instead, and how can I fix it?

© Stack Overflow or respective owner

Related posts about laravel