laravel 文件上传
来源:互联网 发布:网络的发展阶段100字 编辑:程序博客网 时间:2024/05/17 13:07
文件上传
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
<formclass="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; //uploads为config/filesystems里自定义 $bool = Storage::disk('uploads')->put($fileName, file_get_contents($realPath)); print_r($bool);exit; } } return view('student.upload');}
- laravel 文件上传
- laravel如何上传文件
- laravel之文件上传
- Laravel 教程 - 文件上传
- laravel处理文件上传
- laravel文件上传
- Laravel之文件上传
- Laravel之文件上传
- laravel文件上传
- 【笔记】laravel上传文件
- laravel文件上传
- Laravel文件上传
- laravel-文件上传处理
- Laravel之文件上传
- laravel 文件上传
- Laravel--ajax--文件上传
- Laravel 文件上传方法
- laravel(二)laravel文件上传
- APP之底部导航
- NYOJ-ACM-韩信点兵
- 浅谈wordpress后台打开慢/卡顿的解决方法
- centos7 下安装pip pip3
- 论文发表流程注意事项
- laravel 文件上传
- 【curl和wget命令】模拟HTTP请求
- form表单序列化数据之后追加额外数据
- HttpAsyncClients与MultipartEntity
- Android中的PID,TID和UID (关于AIDL的demo)
- 图像卷积和滤波的区别
- Handler&HandlerThread
- 分享到微博,空间
- Unity Lua Enum