【发布时间】:2019-03-14 05:27:43
【问题描述】:
是否可以为新创建的文件夹设置 umask
Storage::disk('sftp')->put('/path/to/folder/new/test.txt', $contents);
在我的例子中,使用的 umask 是 744。是否可以为新创建的文件夹更改 umask?
提前致谢。
【问题讨论】:
标签: laravel filesystems sftp umask
是否可以为新创建的文件夹设置 umask
Storage::disk('sftp')->put('/path/to/folder/new/test.txt', $contents);
在我的例子中,使用的 umask 是 744。是否可以为新创建的文件夹更改 umask?
提前致谢。
【问题讨论】:
标签: laravel filesystems sftp umask
解决方案是在config.xml中使用'directoryPerm' => 0755,键值。配置:
'disks' => [
'remote-sftp' => [
'driver' => 'sftp',
'host' => '222.222.222.222',
'port' => 22,
'username' => 'user',
'password' => 'password',
'visibility' => 'public', // set to public to use permPublic, or private to use permPrivate
'permPublic' => 0755, // whatever you want the public permission is, avoid 0777
'root' => '/path/to/web/directory',
'timeout' => 30,
'directoryPerm' => 0755, // whatever you want
],
],
在代码中,文件 /private/var/www/megalobiz/vendor/league/flysystem-sftp/src/StfpAdapter 中的类 League\Flysystem\Sftp\StfpAdapter 有两个重要的属性可以清楚地看到:
/**
* @var array
*/
protected $configurable = ['host', 'hostFingerprint', 'port', 'username', 'password', 'useAgent', 'agent', 'timeout', 'root', 'privateKey', 'passphrase', 'permPrivate', 'permPublic', 'directoryPerm', 'NetSftpConnection'];
/**
* @var int
*/
protected $directoryPerm = 0744;
$configurable 是配置上述文件系统 sftp 驱动程序的所有可能键。您可以在配置文件中将directoryPerm 从0744 更改为0755:
'directoryPerm' => 0755,
但是,因为在 StfpAdapter https://github.com/thephpleague/flysystem-sftp/issues/81 中存在类似的错误,它不会在 createDir 上使用 $config 参数:
$filesystem = Storage::disk('remote-sftp');
$filesystem->getDriver()->getAdapter()->setDirectoryPerm(0755);
$filesystem->put('dir1/dir2/'.$filename, $contents);
或者故意设置为public:
$filesystem->put('dir1/dir2/'.$filename, $contents, 'public');
【讨论】:
就我而言,在sftpAdapter 的配置中使用所需的umask 设置directoryPerm 就足够了
【讨论】:
你可以使用这个功能:
File::makeDirectory($path, $mode = 0777, true, true);
在您的情况下,只需将 $mode 更改为 0774 :
Storage::disk('sftp')->makeDirectory($path, 0774);
【讨论】: