亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Laravel框架實(shí)現(xiàn)文件上傳的方法分析

 更新時(shí)間:2019年09月29日 10:36:11   作者:學(xué)知無涯  
這篇文章主要介紹了Laravel框架實(shí)現(xiàn)文件上傳的方法,結(jié)合實(shí)例形式分析了Laravel框架文件上傳相關(guān)的配置設(shè)置、視圖及控制器相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了Laravel框架實(shí)現(xiàn)文件上傳的方法。分享給大家供大家參考,具體如下:

配置文件:

config/filesystems.php,

新建存儲(chǔ)空間

'uplaods' => [
  'driver' => 'local',
  'root' => storage_path('app/uploads'),
],

視圖中:

頭像:

<input type="file" name="headimg" />

控制器:

$file = $request->file('headimg');
if($file && $file->isValid()){
//   //獲取原圖片信息
    $ext = $file->getClientOriginalExtension();
    $originalName = $file->getClientOriginalName();
    $type = $file->getClientMimeType();
    $path = $file->getRealPath();
    //驗(yàn)證圖片類型,大小等
    //保存圖片
    $save_name = date('YmdHis',time()) .'-' .uniqid() .'.'. $ext;
    $bool = Storage::disk('uploads')->put($save_name,file_get_contents($path));
    if(!$bool){
      return redirect()->back()->withErrors('圖片上傳失敗')->withInput();
    }
}else{
    return redirect()->back()->withErrors('請(qǐng)上傳圖片')->withInput();
}
//如果驗(yàn)證通過,則繼續(xù)執(zhí)行下面的代碼
$data = $request->input('Student');
//圖片全路徑
$img_web_path = storage_path('app/uploads') . '/' .$save_name;
//圖片相對(duì)路徑
$data['headimg'] = $save_name;
if(Student::create($data)){
    return redirect('Student/index')->with('success','添加成功');
}else{
    return redirect()->back();
}

更多關(guān)于Laravel相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Laravel框架入門與進(jìn)階教程》、《php優(yōu)秀開發(fā)框架總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php+mysql數(shù)據(jù)庫(kù)操作入門教程》及《php常見數(shù)據(jù)庫(kù)操作技巧匯總

希望本文所述對(duì)大家基于Laravel框架的PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論