日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

laravel 文件上传

發布時間:2025/5/22 编程问答 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 laravel 文件上传 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文件上傳

Laravel的文件系統是基于Frankde Jonge的Flysystem擴展包

提供了簡單的接口,可以操作本地端空間,Amazons3,Rackspace Cloud Storage

可以非常簡單的切換不同保存方式,但仍使用相同的API操作

?

配置文件

1.Config/filesystems.php

??? 'disks' => [

??????? 'local' => [

??????????? 'driver' => 'local',

??????????? 'root' => storage_path('app'),

??????? ],

??????? 'public' => [

??????????? 'driver' => 'local',

??????????? 'root' =>storage_path('app/public'),

??????????? 'visibility' => 'public',

??????? ],

???????????????????? //新建立一個uploads

??????? 'uploads' =>[

??????????? 'driver' => 'local',

??????????? //storage_path對應的是目錄下storage

??????????? 'root' =>storage_path('app/uploads'),

???????? ???'visibility' => 'public',

??????? ],

??????? 's3' => [

??????????? 'driver' => 's3',

??????????? 'key' => 'your-key',

??????????? 'secret' => 'your-secret',

??????????? 'region' => 'your-region',

??????????? 'bucket' => 'your-bucket',

??????? ],

],

2.view

<form class="form-horizontal" method="POST" action="" enctype="multipart/form-data">
???
{{csrf_field() }}

???
<div class="form-group{{$errors->has('password') ? ' has-error' : '' }}">
??????? <label
for="password" class="col-md-4 control-label">請選擇文件</label>

??????? <div
class="col-md-6">
??????????? <input
id="file" type="file" class="form-control" name="source" required>
??????? </div>
??? </div>


??? <div
class="form-group">
??????? <div
class="col-md-8 col-md-offset-4">
??????????? <button
type="submit" class="btn btn-primary">
???????????????
確認上傳
???????????
</button>
??????? </div>
??? </div>
</form>

?

3.controllers

public function upload(Request $request) {if($request->isMethod('POST')) {//print_r($_FILES);//source表單名$file = $request->file('source');//文件是否上傳成功if($file->isValid()) {//取原文件名$originalName = $file->getClientOriginalName();//取擴展名$ext = $file->getClientOriginalExtension();//取文件類型$type = $file->getClientMimeType();//臨時文件的絕對路徑$realPath = $file->getRealPath();//定義文件名$fileName = date("YmdHis"). '-' . uniqid(). '.' . $ext;//uploadsconfig/filesystems里自定義$bool = Storage::disk('uploads')->put($fileName, file_get_contents($realPath));print_r($bool);exit;}}return view('student.upload'); }

總結

以上是生活随笔為你收集整理的laravel 文件上传的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。