# Storage 保存文件

這邊只介紹FTP跟專案資料夾，關於如何架設FTP伺服器請點擊[傳送門](https://www.gitbook.com/book/judechih/integrated/edit#/edit/master/chapter1.md?_k=saxbhk)

## 設定

先做連接

```php
php artisan storage:link
```

其它設定都在`\config\filesystems.php`如下:

```php
<?php

return [

    'default' => 'ftp', // Supported: "local", "ftp", "s3", "rackspace"

    'cloud' => 'ftp', // 預設是'cloud' => 's3',

    'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'visibility' => 'public',
        ],

        's3' => [
            'driver' => 's3',
            'key' => 'your-key',
            'secret' => 'your-secret',
            'region' => 'your-region',
            'bucket' => 'your-bucket',
        ],

        'ftp' => [ // 你所架設的FTP的設定在這邊
            'driver'   => 'ftp',
            'host' => '192.168.30.212',
            'username' => 'root',
            'password' => '12347890',
        ],

    ],

];
```

## 功能

```php
// 設置跟取得該文件的可見度
    Storage::setVisibility('new/jjde.txt','private');
    $val = Storage::getVisibility('new/jjde.txt');

// 取得該文件的內容
    $data = Storage::disk('public')->get('new/file6.txt'); // 還可以指定你要抓哪個資料夾得哪個disk的
    Storage::put('file.jpg', $data ); // 抓取到的內容，可以生成出另一個文件，可以移到你想要存放的disk的某個資料夾

// 查詢該文檔的字數
    $size = Storage::size('new/jjde.txt');

// 在文件的內容最前面輸入後面的字串
    Storage::prepend('new/file3.txt', 'Prepended Text');
    Storage::append('new/file3.txt', 'Prepended Text');

// 移動wtf里面的某個文件，到new資料夾里，並且給他一個名稱
    Storage::move('wtf/4e22ca05856c57fa31741cf11d40eb69.txt', 'new/file3.txt'); // 就像是剪下後貼到其他地方
    Storage::copy('old/file1.jpg', 'new/file1.jpg'); //就像是複製後貼到其他地方

// 複製某個文件，並且給他一個名稱，到new的資料夾
    Storage::putFileAs('new', new File('upload/text/1490771882_file.txt'), 'jjde.txt','private');

// 檢查文件是否存在
    $boolean = Storage::disk('ftp')->exists('new/file3.txt'); 

// 刪除指定文件
    Storage::delete('file.jpg'); // 可單一刪除
    Storage::delete(['file1.jpg', 'file2.jpg']); // 可複選刪除
```

還有很多其他的功能，這邊只列出我用過的，其他的請點擊這個[傳送門](http://d.laravel-china.org/docs/5.3/filesystem)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tobyisme.gitbook.io/laravel/storage-bao-cun-wen-jian.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
