我有在我的代码上传文件到谷歌驱动器的问题,当我使用包nao-pon/flysystem-google-drive时,此代码将创建子目录=“合同”,但我有许多不同名称的文件夹,他们是相同的2个文件夹的孩子是:合同,项目。我找不到在我想要的文件夹名称中创建text.txt的方法
我正在尝试修复查询
$dir = $contents->where('type', '=', 'dir')
->where('filename', '=', 'Contract')
->first();但它不起作用。
Route::get('put-in-dir', function() {
$dir = '/';
$recursive = true; // Get subdirectories also?
$contents = collect(Storage::cloud()->listContents($dir, $recursive));
$dir = $contents->where('type', '=', 'dir')
->where('filename', '=', 'Contract')
->first(); // There could be duplicate directory names!
if ( ! $dir) {
return 'Directory does not exist!';
}
Storage::cloud()->put($dir['path'].'/test.txt', 'Hello World');
return 'File was created in the sub directory in Google Drive';
});我想在我想要的顺序中创建text.txt。例:我想在Yasuo的合同中创建..
Shaco-
--Contract
--Project
Yasuo-
--Contract
--Project发布于 2019-01-16 11:52:04
我找到了解决方案。这是我的解决方案:
Route::get('put-in-dir', function() {
$content = collect(Storage::cloud()->listContents('/', false));
foreach ($content as $key => $value) {
if($value['name'] == 'MrTrung')
$root = $value['path'];
}
//dd($root);
$dir = '/'.$root;
$recursive = true; // Get subdirectories also?
$contents = collect(Storage::cloud()->listContents($dir, $recursive));
$dir = $contents->where('type', '=', 'dir')
->where('filename', '=', 'Contract')
->first(); // There could be duplicate directory names!
if ( ! $dir) {
return 'Directory does not exist!';
}
Storage::cloud()->put($dir['path'].'/test.txt', 'Hello World');
return 'File was created in the sub directory in Google Drive';
});注意:当你安装google drive API v3时,一切都是正确的。我遵循这样的方式:https://gist.github.com/ivanvermeyen/cc7c59c185daad9d4e7cb8c661d7b89b
祝好运。
https://stackoverflow.com/questions/54209376
复制相似问题