Php 如何使用Laravel4创建文件输入并存储到数据库中?
到目前为止,由于某种原因 我无法将其保存到数据库 我已经检查过了 有人能告诉我我做错了什么吗 但由于某种原因,该文件保存到我的本地系统Php 如何使用Laravel4创建文件输入并存储到数据库中?,php,laravel-4,Php,Laravel 4,到目前为止,由于某种原因 我无法将其保存到数据库 我已经检查过了 有人能告诉我我做错了什么吗 但由于某种原因,该文件保存到我的本地系统 $user = new User; $user->firstname = Input::get('firstname'); $user->lastname = Input::get('lastname'); $user->username = Input::get
$user = new User;
$user->firstname = Input::get('firstname');
$user->lastname = Input::get('lastname');
$user->username = Input::get('username');
$user->email = Input::get('email');
$logo_path = Input::file('logo_path');
if (Input::hasFile('logo_path'))
{
$file = Input::file('logo_path');
$destinationPath = base_path().'/app/files/logo_path/';
$filename = $file->getClientOriginalName();
$uploadSuccess = $file->move($destinationPath, $filename);
$user->logo_path = $filename;
}
return Redirect::to('/users/')
->with('success',' Your Account has been created');
}
我注意到你忘了一件最重要的事 试试这个
$user->save()代码>返回前重定向。让我知道。您没有执行save()方法,您的代码应该是
$user = new User;
$user->firstname = Input::get('firstname');
$user->lastname = Input::get('lastname');
$user->username = Input::get('username');
$user->email = Input::get('email');
if (Input::hasFile('logo_path'))
{
$allowedext = array("png","jpg","jpeg","gif");
$photo = Input::file('logo_path');
$destinationPath = public_path().'/uploads';
$filename = str_random(12);
$extension = $photo->getClientOriginalExtension();
if(in_array($extension, $allowedext ))
{
$upload_success = Input::file('logo_path')->move($destinationPath, $filename.'.'.$extension);
}
}
$user->photo=$filename;
$user->save();
请注意变量名是否有错误消息?您能否详细说明所需的行为并为您的问题添加更多细节?