我有以下商店方法来上传文件。
public function store()
{
//
$rules = [];
$validator = Validator::make(Input::all(), $rules);
// if the validator fails, redirect back to the form
if ($validator->fails()) {
return Redirect::back()
->withErrors($validator) // send back all errors to the login form
->withInput();
} else {
$klas = new Klas;
$klas ->title = Input::get('title');
if (Input::get('active') === 'yes') {
$klas ->active = 1;
} else {
$klas ->active = 0;
}
$extension = 'png';
$directory = public_path() . '/uploads/klassen';
$filename = Input::get('title').".{$extension}";
$upload_success = Input::file('image',$directory,$filename);
//Upload the file
if($upload_success){
$klas->image = $filename;
$klas -> save();
$klassen = DB::table('klas')->get();
return View::make('klas.index',compact('klassen'));
}
}
}
我的'klas'
也使用正确的文件名成功保存到数据库中。但文件没有上传?我已经将public , uploads and klassen folder
设置为已经为每个人阅读。
任何帮助?
答案 0 :(得分:1)
您必须将文件移动到目标目录:
$file = Input::file('image');
$file->move($directory, $filename);
我不确定你现在正在做第二和第三个论点是否有效。