reaway/think-filesystem-driver-sftp

thinkphp filesystem sftp driver

v1.0.0 2025-07-02 06:09 UTC

This package is auto-updated.

Last update: 2025-07-02 06:10:29 UTC


README

安装

composer require reaway/think-filesystem-driver-sftp

用法

在config/filesystem.php添加配置

return [
    'default' =>  'local',
    'disks'   => [
        'local'  => [
            'type' => 'local',
            'root'   => app()->getRuntimePath() . 'storage',
        ],
        'public' => [
            'type'     => 'local',
            'root'       => app()->getRootPath() . 'public/storage',
            'url'        => '/storage',
            'visibility' => 'public',
        ],
        // 添加配置
         'sftp'  => [
            'type' => 'sftp',
            'root' => 'uploads',
            'connection' => [
                'host' => '127.0.0.1',
                // 基于基础的身份验证设置...
                'username' => 'username',
                'password' => 'password',
                // 可选的 SFTP 设置
                'port' => 22,
            ]
        ],
    ],
];

使用

use think\facade\Filesystem;

$savename = Filesystem::disk('sftp')->putFile('topic', $file);

文档

详细参考 https://doc.thinkphp.cn/v8_0/upload.html