上传时,除pic_path列包含0外,所有数据都插入到表中。上传处理文件时我做错了:
这是控制器:
if(Session::has('userLogged'))
{
if($_POST)
{
$file;
if (Input::hasFile('pic'))
{
$file = Input::file('pic');
print_r($file);
}
$validator = $this->validate(Input::all(), $rules);
if ($validator != null)
{
return Redirect::to('basicDetails')->withErrors($validator);
}else{
$title = Input::get('title');
$summary = Input::get('summary');
$description = Input::get('description');
$destinationPath = base_path() . '/public/img';
$file->move($destinationPath);
$path = $file->getRealPath();
$personModel = new Course;
$personeModel->basicDetails($title, $summary, $description, $path);
}
这是表单url:
{{ Form::open(array('action' => 'PersonController@basic','files' => true)) }}
谢谢,
答案 0 :(得分:1)
在移动文件之前获取路径:
$title = Input::get('title');
$summary = Input::get('summary');
$description = Input::get('description');
$destinationPath = base_path() . '/public/img';
$path = $file->getRealPath();
$file->move($destinationPath);
$personModel = new Course;
$personeModel->basicDetails($title, $summary, $description, $path);
我不确定你为什么需要上传路径?通常这是Laravel上传文件的临时路径。