好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > Laravel5.1 框架文件管理操作實例分析

Laravel5.1 框架文件管理操作實例分析

熱門標簽:百應電話機器人服務 岳陽外呼型呼叫中心系統在哪里 騰訊外呼管理系統 昭通辦理400電話 揚州地圖標注app 山西探意電話機器人 河南電銷卡外呼系統哪家強 山西回撥外呼系統 青島語音外呼系統招商

本文實例講述了Laravel5.1 框架文件管理操作。分享給大家供大家參考,具體如下:

Laravel提供了一套很好用的文件系統 方便于管理文件夾和文件,支持Amazon S3和Rackspace云存儲等驅動。

1 配置

文件系統的配置文件在 config/filesyetems.php 中,且它的注釋寫的很清楚了,此外你可以在disks數組中創建新的disk:

?php
return [
  /*
  |--------------------------------------------------------------------------
  | Default Filesystem Disk
  |--------------------------------------------------------------------------
  |
  | Here you may specify the default filesystem disk that should be used
  | by the framework. A "local" driver, as well as a variety of cloud
  | based drivers are available for your choosing. Just store away!
  |
  | Supported: "local", "ftp", "s3", "rackspace"
  |
  */
  'default' => 'local',
  /*
  |--------------------------------------------------------------------------
  | Default Cloud Filesystem Disk
  |--------------------------------------------------------------------------
  |
  | Many applications store files both locally and in the cloud. For this
  | reason, you may specify a default "cloud" driver here. This driver
  | will be bound as the Cloud disk implementation in the container.
  |
  */
  'cloud' => 's3',
  /*
  |--------------------------------------------------------------------------
  | Filesystem Disks
  |--------------------------------------------------------------------------
  |
  | Here you may configure as many filesystem "disks" as you wish, and you
  | may even configure multiple disks of the same driver. Defaults have
  | been setup for each driver as an example of the required options.
  |
  */
  'disks' => [
    'local' => [
      'driver' => 'local',
      'root'  => storage_path('app'),
    ],
    'ftp' => [
      'driver'  => 'ftp',
      'host'   => 'ftp.example.com',
      'username' => 'your-username',
      'password' => 'your-password',
      // Optional FTP Settings...
      // 'port'   => 21,
      // 'root'   => '',
      // 'passive' => true,
      // 'ssl'   => true,
      // 'timeout' => 30,
    ],
    's3' => [
      'driver' => 's3',
      'key'  => 'your-key',
      'secret' => 'your-secret',
      'region' => 'your-region',
      'bucket' => 'your-bucket',
    ],
    'rackspace' => [
      'driver'  => 'rackspace',
      'username' => 'your-username',
      'key'    => 'your-key',
      'container' => 'your-container',
      'endpoint' => 'https://identity.api.rackspacecloud.com/v2.0/',
      'region'  => 'IAD',
      'url_type' => 'publicURL',
    ],
  ],
];

一般情況下最常用的是local(本地)存儲,所以特別說下,我們可以通過修改'root'來修改我們的root路徑:

    'local' => [
      'driver' => 'local',
//      'root'  => storage_path('app'), 在/storage/app/目錄
      'root'  => public_path('uploads'), // 在public/uploads/ 目錄
    ],

2 獲取硬盤實例

要進行文件管理需要那到硬盤實例,我們可以通過 Storage 門面的 disk 方法來獲取,之后就可以進行我們想要的操作了:

  public function index()
  {
    $disk = Storage::disk('local');
    // 創建一個文件
    $disk->put('file1.txt', 'Laravel Storage');
  }

3 文件操作

3.1 獲取文件

public function index()
  {
    // 取到磁盤實例
    $disk = Storage::disk('local');
    // 取出文件
    $file = $disk->get('test.txt');
    dd($file);
  }

我們可以使用get()方法獲取到文件 以字符串的形式傳入文件名就行,但是需要主意:如果你要取到子目錄以下的文件時需要傳入路徑,比如:$disk->get('subpath/.../.../.../file.txt');

3.2 判斷文件是否存在

  public function index()
  {
    // 取到磁盤實例
    $disk = Storage::disk('local');
    // 取出文件
    $exists = $disk->exists('image.png');
    dd($exists);  // false
  }

3.3 獲取文件信息

文件大小:

  public function index()
  {
    // 取到磁盤實例
    $disk = Storage::disk('local');
    // 取出文件
    $size = Storage::size('/home/test.txt');
    dd($size); // 4
  }

最后修改時間:

  public function index()
  {
    // 取到磁盤實例
    $disk = Storage::disk('local');
    // 取出文件
    $time = Storage::lastModified('file1.txt');   // 1507701271
    $time = Carbon::createFromTimestamp($time);
    echo $time;   // 2017-10-11 05:54:31
  }

3.4 儲存文件

  public function index()
  {
    // 取到磁盤實例
    $disk = Storage::disk('local');
    // 儲存文件
    $disk->put('file2.txt', 'file2 content'); // 新建一個文件
  }

3.5 Copy文件

  public function index()
  {
    // 取到磁盤實例
    $disk = Storage::disk('local');
    // 拷貝文件 第一個參數是要拷貝的文件,第二個參數是拷貝到哪里
    $disk->copy('home/test.txt','rename.txt');
  }

3.6 移動文件

  public function index()
  {
    // 取到磁盤實例
    $disk = Storage::disk('local');
    // 拷貝文件 第一個參數是要移動的文件,第二個參數是移動到哪里
    $disk->move('file2.txt', 'home/file.txt');
  }

3.7 在文件開頭/結尾添加內容

  public function index()
  {
    // 取到磁盤實例
    $disk = Storage::disk('local');
    // 在文件開頭添加
    $disk->prepend('file1.txt', 'test prepend');
    // 在文件末尾添加
    $disk->append('file1.txt', 'test append');
  }

3.8 刪除文件

  public function index()
  {
    // 取到磁盤實例
    $disk = Storage::disk('local');
    // 刪除單條文件
    $disk->delete('test.txt');
    // 刪除多條文件
    $disk->delete(['test22.txt', 'icon.jpg']);
  }

4 目錄操作

4.1 取到目錄下的文件

  public function index()
  {
    // 取到磁盤實例
    $disk = Storage::disk('local');
    $directory = '/';
    // 獲取目錄下的文件
    $files = $disk->files($directory);
    // 獲取目錄下的所有文件(包括子目錄下的文件)
    $allFiles = $disk->allFiles($directory);
    dd($files, $allFiles);
  }

4.2 取到子目錄

  public function index()
  {
    // 取到磁盤實例
    $disk = Storage::disk('local');
    $directory = '/';
    // 獲取目錄下的子目錄
    $directories = $disk->directories($directory);
    // 獲取目錄下的所有子目錄(包括子目錄下的子目錄)
    $allDirectories = $disk->allDirectories($directory);
    dd($directories, $allDirectories);
  }

4.3 創建目錄

  public function index()
  {
    // 取到磁盤實例
    $disk = Storage::disk('local');
    // 創建目錄
    $disk->makeDirectory('test');
    $disk->makeDirectory('test1/test2');
  }

4.4 刪除目錄

  public function index()
  {
    // 取到磁盤實例
    $disk = Storage::disk('local');
    // 刪除目錄
    $disk->deleteDirectory('test');
    $disk->deleteDirectory('test1/test2');
  }

更多關于Laravel相關內容感興趣的讀者可查看本站專題:《Laravel框架入門與進階教程》、《php優秀開發框架總結》、《php面向對象程序設計入門教程》、《php+mysql數據庫操作入門教程》及《php常見數據庫操作技巧匯總》

希望本文所述對大家基于Laravel框架的PHP程序設計有所幫助。

您可能感興趣的文章:
  • Laravel 5使用Laravel Excel實現Excel/CSV文件導入導出的功能詳解
  • vuejs+element-ui+laravel5.4上傳文件的示例代碼
  • 修改Laravel5.3中的路由文件與路徑
  • 在Laravel5中正確設置文件權限的方法
  • PHP框架laravel的.env文件配置教程
  • Laravel最佳分割路由文件(routes.php)的方式
  • PHP Laravel 上傳圖片、文件等類封裝
  • PHP Laravel實現文件下載功能
  • Laravel框架文件上傳功能實現方法示例
  • Laravel基礎-關于引入公共文件的兩種方式
  • 使用laravel指定日志文件記錄任意日志

標簽:鎮江 宜賓 黃南 婁底 銅川 寶雞 南陽 湛江

巨人網絡通訊聲明:本文標題《Laravel5.1 框架文件管理操作實例分析》,本文關鍵詞  Laravel5.1,框架,文件,管理,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《Laravel5.1 框架文件管理操作實例分析》相關的同類信息!
  • 本頁收集關于Laravel5.1 框架文件管理操作實例分析的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: chinese情侣自拍啪hd| 欧美性生活网| 三上悠亚教室高无删减版| 车子一晃一晃就c进肉了| 男人日女人逼逼| 51漫画成长人版安装testflight安卓| 粉嫩欧美一区二区三区高清影视| 周秀娜罗仲谦无删减版| 亚洲人成免费网站| 双人床上互动模拟器| 久久香蕉影视| 又粗又大爽死我| 闺蜜张开腿让我爽了一夜女同| 51久久精品一二三区色欲Av| 巨胸大罩杯艳妇小说| 美人集卡游戏(总_攻)| 国产精品久久久久精品香蕉剃毛| 久久国产精品欧美熟妇AV电影| 国产超级乱淫片中文| 亚洲午夜剧场| 欧美疯狂做受XXXX高潮蜜臀| 狠狠操亚洲| 50岁寡妇下面水多好紧| 性感美女福利视频| 厨房脱岳裙子在后面挺进| 菠萝在线ALEVEL| 肉丝袜| 国产欧美二区三区| 青草青青在线| 嗯啊好爽好大| 久久精品国产一区二区三区肥胖| 91精品啪在线观看国产91九色| 国产日韩欧美视频在线| 另类圣水喝尿调教| 俺去啦视频| 国产精品久久天天躁| 欧美精品亚洲二区| 美国黄色大片| 欧美激情欧美在线播放| 国产日产久久久久久精品加勒比| 尤物视频一区二区|