laravel文件上传
程序员文章站
2022-04-05 10:10:17
$file = Request::file('photo');//文件 $name = input::get('name');//其他属性值 $allowed_extensions = ["png", "jpg", "gif"]; if ($file->getClientOriginalExtens... ......
$file = request::file('photo');//文件 $name = input::get('name');//其他属性值 $allowed_extensions = ["png", "jpg", "gif"]; if ($file->getclientoriginalextension() && !in_array($file->getclientoriginalextension(), $allowed_extensions)) { return ['error' => 'you may only upload png, jpg or gif.']; } $destinationpath = 'storage/uploads/'; //public 文件夹下面建 storage/uploads 文件夹 $extension = $file->getclientoriginalextension(); $filename = str_random(10).'.'.$extension; $file->move($destinationpath, $filename); $filepath = asset($destinationpath.$filename); $info=db::insert('insert into photo(pname,photo) values (?,?)',[$name,$filepath]);//入库 if($info){ return redirect('/show'); }else{ echo "no"; }
上一篇: npm包发布记录
下一篇: 三国时期关羽从不主动与吕布单挑,是为何?