记录一下 Laravel Storage 的常见用法

内容写入磁盘文件

> php artisan tinker
>>> use Illuminate\Support\Facades\Storage;
>>> Storage::put('test.txt', 'hello');
=> true ls storage/app/
public/ test.txt

文件默认创建在 /storage/app 目录下

获取文件存储的本地磁盘全路径

继续在 tinker 中测试一下

>>> storage_path()
=> "/home/zhongwei/work/my_project/storage"
>>> storage_path('test.txt')
=> "/home/zhongwei/work/my_project/storage/test.txt"
>>> storage_path('app/test.txt')
=> "/home/zhongwei/work/my_project/storage/app/test.txt"

可见,应该是 storage_path('app/test.txt')

删除文件

>>> Storage::delete('test.txt')
=> true

文件默认存储路径是在哪里设置的

Config/filesystems.php

    'disks' => [

        'local' => [
'driver' => 'local',
'root' => storage_path('app'),
], 'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],

Local.root 指定的即是默认路径。

判断一个文件是否存在

>>> Storage::put('public/test.txt', 'hello');
=> true
>>> Storage::exists('public/test.txt');
=> true
>>> Storage::exists('public/test1.txt');
=> false

最新文章

  1. ReactJS尝鲜:实现tab页切换和菜单栏切换和手风琴切换效果,进度条效果
  2. CentOS下通过yum安装svn及配置
  3. Tensorflow学习笔记2:About Session, Graph, Operation and Tensor
  4. [ASP.NET] 使用Loading遮罩防止使用者重複點擊
  5. swift系统学习第一章
  6. set_exception_handler 和 set_error_handler 函数
  7. “System.Exception: System.Data.OracleClient 需要 Oracle 客户端软件 8.1.7 或更高版本” 的解决方案
  8. 总结:常用的Linux系统监控命令
  9. Android UI -- 布局介绍(布局包括FrameLayout, LinearLayout, RelativeLayout, GridLayout)
  10. SharePoint 2013 更新多个用户字段(Person or Group)
  11. HTML学习(1)
  12. 新浪微博iOS示例,登录,获取个人信息
  13. (转)js prototype 详解
  14. android 向serverGet和Post请求的两种方式,android向server发送文件,自己组装协议和借助第三方开源
  15. ASP.NET Core开发之HttpContext
  16. Goland配置
  17. 1,环境的搭建,angular
  18. GMA Round 1 向量计算
  19. [hive] hive 内部表和外部表
  20. 获取CNVD的cookie

热门文章

  1. 安装Cloudera manager Server步骤详解
  2. strace常用参数详解
  3. Java POI 读取word文件
  4. URLConnection 和 HttpClients 发送请求范例【原】
  5. python学习笔记8--面向对象--属性和方法详解
  6. ICS Hack Tools
  7. VS中修改工程名的解决方案
  8. C# 面向对象的base的使用
  9. JavaScript之JS单线程|事件循环|事件队列|执行栈
  10. Linux 之【辨析UPDATE/UPGRADE】和安装/卸载软件(apt-get)