Php Laravel 5.4图像上传
我是新来的拉威尔,想学习图像上传。我曾经用Codeigniter很容易做到这一点,但我发现在Laravel很难做到 以下是我在Codeigniter中经常做的事情:Php Laravel 5.4图像上传,php,laravel,laravel-5.4,Php,Laravel,Laravel 5.4,我是新来的拉威尔,想学习图像上传。我曾经用Codeigniter很容易做到这一点,但我发现在Laravel很难做到 以下是我在Codeigniter中经常做的事情: $prof_pic = $_FILES['profile_pic']['name']; if($prof_pic != '') { $config = array ('upload_path' => './images/students/',
$prof_pic = $_FILES['profile_pic']['name'];
if($prof_pic != '')
{
$config = array ('upload_path' => './images/students/',
'allowed_types' => "jpeg|jpg|png",
'overwrite' => TRUE,
'file_name' => str_replace(' ','-',$Maxtype."-".$fname."-".$lname)
);
$this->load->library('upload', $config);
$this->upload->do_upload('profile_pic');
$extension = pathinfo($prof_pic);
$ext = $extension['extension'];
$image = str_replace(' ','-',$config['file_name'].".".$ext);
} else {
$image = 'no_pic.jpg';
$ext = 'jpg';
}
有没有办法在Laravel中使用此代码?我在Laravel中尝试了以下代码,但它显示了一些错误
$this->validate($request, ['company_logo' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:1024',]);
$imageName = time().'.'.$request->company_logo->getClientOriginalExtension();
$request->company_logo->move(public_path('company_logo'), $imageName);
return back()->with('success','Record Created');
这就是错误:
LogicException in MimeTypeGuesser.php line 135:
Unable to guess the mime type as no guessers are available (Did you enable the php_fileinfo extension?)
看看下面的博客页面,这可能会对你有所帮助。
我强烈建议在来到这里之前使用laravel文档,它非常详细。对于文件上传,您可以通过阅读文档或观看Laracast来学习。