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?
You should try to do some checking before trying to upload the attachment. This works for me:
$file = Input::file('attachment1');
if (is_array($file) && isset($file['error']) && $file['error'] == 0) {
Input::upload('attachment1',path('storage').'attachments/'.$name);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With