问题
Getting the following error
Unable to create the "http://website.com/public/uploads/" directory
My code:
$file = Input::file('upload');
$file_name = $file->getClientOriginalName();
$file_size = round($file->getSize() / 1024);
$file_ex = $file->getClientOriginalExtension();
$file_mime = $file->getMimeType();
if (!in_array($file_ex, array('jpg', 'gif', 'png'))) return Redirect::to('/')->withErrors('Invalid image extension we just allow JPG, GIF, PNG');
$newname = $file_name;
$file->move(URL::to('/').'/uploads/', $newname);
The uploads folder exists.
回答1:
You are trying to move a file to a URL, you have to move to a folder:
$file->move(base_path().'/public/uploads/', $newname);
回答2:
It can also be done like this:
$file->move('uploads', $newname);
For a unique file name, you can add time() function like this:
$file_name = time().$file->getClientOriginalName();
$file->move('uploads', $newname);
来源:https://stackoverflow.com/questions/20805175/laravel-file-upload