是否可以为新创建的文件夹设置umask
Storage::disk('sftp')->put('/path/to/folder/new/test.txt', $contents);
在我的例子中,使用的umask是744。是否可以更改新创建的文件夹的umask?
提前谢谢。
发布于 2018-10-09 13:30:18
在我的示例中,只需在directoryPerm
的配置中使用所需的umask设置sftpAdapter
即可。
发布于 2018-10-09 12:27:27
您可以使用此函数:
File::makeDirectory($path, $mode = 0777, true, true);
在您的示例中,只需将$mode更改为0774:
Storage::disk('sftp')->makeDirectory($path, 0774);
发布于 2020-12-25 17:36:51
解决方案是在配置中使用'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
],
],
在代码中,即文件League\Flysystem\Sftp\StfpAdapter
中的/private/var/www/megalobiz/vendor/league/flysystem-sftp/src/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中有一种类似于Bug的类型,它不会在createDir
上使用$config参数
$filesystem = Storage::disk('remote-sftp');
$filesystem->getDriver()->getAdapter()->setDirectoryPerm(0755);
$filesystem->put('dir1/dir2/'.$filename, $contents);
或以公众为目的:
$filesystem->put('dir1/dir2/'.$filename, $contents, 'public');
https://stackoverflow.com/questions/52720952
复制相似问题