首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用laravel将子文件夹中的文件放到google驱动器中

使用laravel将子文件夹中的文件放到google驱动器中
EN

Stack Overflow用户
提问于 2019-01-16 09:53:12
回答 1查看 1.2K关注 0票数 0

我有在我的代码上传文件到谷歌驱动器的问题,当我使用包nao-pon/flysystem-google-drive时,此代码将创建子目录=“合同”,但我有许多不同名称的文件夹,他们是相同的2个文件夹的孩子是:合同,项目。我找不到在我想要的文件夹名称中创建text.txt的方法

我正在尝试修复查询

代码语言:javascript
复制
$dir = $contents->where('type', '=', 'dir')
    ->where('filename', '=', 'Contract')
    ->first();

但它不起作用。

代码语言:javascript
复制
    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的合同中创建..

代码语言:javascript
复制
Shaco-
  --Contract
  --Project
Yasuo-
  --Contract
  --Project
EN

回答 1

Stack Overflow用户

发布于 2019-01-16 11:52:04

我找到了解决方案。这是我的解决方案:

代码语言:javascript
复制
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

祝好运。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54209376

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档