路線:
Route::post('uploadFile', '[email protected]');
你的HTML刀片:
<form action="{{ url('uploadFile') }}" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit">
</form>
控制器:
public function uploadFile()
{
//get the file
$file = Input::file('file');
//create a file path
$path = 'uploads/';
//get the file name
$file_name = $file->getClientOriginalName();
//save the file to your path
$file->move($path , $file_name); //(the file path , Name of the file)
//save that to your database
$new_file = new Uploads(); //your database model
$new_file->file_path = $path . $file_name;
$new_file->save();
//return something (sorry, this is a habbit of mine)
return 'something';
}
有用的資源(這些鏈接可能會過期,所以他們只有在這裏爲參考):
Laravel Requests (like Inputs and the such)
File Upload Tutorial that helped me when I started
你嘗試過這麼遠嗎?向我們展示處理上傳的路線和控制器 –
我想指出的一件事是你無法將真實文件保存在數據庫中,而是上傳到文件夾並將文件名存儲在表 – Digitlimit
@Digitlimit ohww ...好的先生,我將創建一個上傳文件的路徑 – angel1108