Here is my routes file
Route::resource('item', 'ItemController');
Route::get('welcome', function() {
return view('welcome');
});
Route::auth();
Route::get('/home', 'HomeController@index');
Route::get('/item', 'ItemController@store');
//Route
Route::post('/item', ['as' => 'item.store', 'uses' => 'ItemController@store']);
Here is my store controller
public function store(Requests\CreateItem $request)
{
Item::create($request->all());
$file = $request->file('filename');
if (Input::hasFile('filename')) {
echo 'Uploaded';
$file = Input::file('filename');
$file->move('uploads', $file->getClientOriginalName());
}
}
My upload form does not return any errors, but this snippet of code is not moving my uploads to the folder specified. What am I doing wrong? I am using Laravel 5.2.
edit: Here is my form
{!! Form::open(['url' =>'route' => 'item.store', 'files' => true]) !!}
{!! Form::label('name', "Name") !!}
{!! Form::text('name', null, ['class' => 'form-control']) !!}
{!! Form::label('filename', "File Name") !!}
{!! Form::file('filename', null, ['class' => 'form-control']) !!}
{!! Form::label('description', 'Description') !!}
{!! Form::textarea('description', null, ['class' => 'form-control']) !!}
{!! Form::submit('Add Item', ['class' => 'btn btn-primary form-control']) !!}
EDIT 2: Now I'm getting the following error upon accessing the form
FatalErrorException in 41b177cdb949fd0263185e364012b35dff81db06.php line 7: syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ']'
EDIT 2 Now I get this error everytime I try to access the add item form:
FatalErrorException in 41b177cdb949fd0263185e364012b35dff81db06.php line 7: syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ']'
Another reason for this is PHP max upload size. Increase value and try again.
Does the <form>
have enctype="multipart/form-data"
on it? It needs this to send the files properly. It's practically an error whenever a <form>
has <input type="file">
elements in it, but doesn't have that attribute.
This is a pretty common mistake, gets people all the time.
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