flysystem-google-drive
flysystem-google-drive copied to clipboard
How to create sub directory
use Hypweb\Flysystem\GoogleDrive\GoogleDriveAdapter;
use League\Flysystem\Filesystem;
$client = new Google_Client();
$client->setAuthConfigFile('path_to_json_file');
$client->setScopes(['https://www.googleapis.com/auth/drive']);
$googleDriveFileManager = new Filesystem(
new GoogleDriveAdapter(
new Google_Service_Drive($client),
'root'
)
);
$result = $googleDriveFileManager->createDir('_test');
echo $result;exit; // displays 1
Result is 1, but there is no created directory on my Google Drive. What is the reason in?
@JILeXanDR Please check result with var_dump($result);
instead to echo $result;
.
@nao-pon It returns bool(true)
Umm... I'm not sure. What is result $googleDriveFileManager->listContents('root');
?
@nao-pon
var_dump(implode(', ', array_pluck($cloud->listContents('root'), 'filename')));exit;
There are a lot of created directories by me. But they are not visible in Google Drive
_test, _test, _test, _test, _test, _test, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, _test, _test, _test, GOOGLE_DRIVE_SYNC, root, GOOGLE_DRIVE_SYNC, GOOGLE_DRIVE_SYNC, _test, _test, Getting started, _test, root, 1111, _test, _test, _test, GOOGLE_DRIVE_SYNC, _test, GOOGLE_DRIVE_SYNC, _test, _test, _test, _test, xxx, _test, _test, GOOGLE_DRIVE_SYNC, _test, _test, _test, GOOGLE_DRIVE_SYNC, test, _test, test, _test, _test, _test, _test, _test, _test, _test, _test, _test, _test, _test, _test, _test, 1111, _test, test, _test, _test, GOOGLE_DRIVE_SYNC, test, _test, _test, _test, _test, GOOGLE_DRIVE_SYNC, _test, 1111, root, _test, _test, _test, _test, _test, _test, _test, _test, _test, _test, GOOGLE_DRIVE_SYNC, _test, _test, _test, _test, GOOGLE_DRIVE_SYNC, GOOGLE_DRIVE_SYNC, _test, test, GOOGLE_DRIVE_SYNC, 1111, _test, _test, _test
For example when I try to create sub-directory (in already created by me but not visible in list)
$cloud->createDir('GOOGLE_DRIVE_SYNC/images');
action is finished with error
[Google_Service_Exception]
{
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "File not found: GOOGLE_DRIVE_SYNC.",
"locationType": "parameter",
"location": "fileId"
}
],
"code": 404,
"message": "File not found: GOOGLE_DRIVE_SYNC."
}
}
Used version is 1.1
Google Drive is ID based filesystem, so this connector need ID based path. e.g. $cloud->createDir('FOLDER ID/images');
Problem with not existed directory was solved. Need use unique "path" instead of real name of directory.
array(8) {
["type"]=>
string(3) "dir"
["path"]=>
string(33) "root/0ByPeQhcJr3-DRDVzd3BFUGZtWU0"
["filename"]=>
string(3) "zip"
["extension"]=>
string(0) ""
["timestamp"]=>
int(1489679824)
["size"]=>
int(0)
["dirname"]=>
string(4) "root"
["basename"]=>
string(28) "0ByPeQhcJr3-DRDVzd3BFUGZtWU0"
}
This code works
$cloud->createDir('root/0ByPeQhcJr3-DRDVzd3BFUGZtWU0/fileOrDirName');
@nao-pon But created files and directories are still not visible in Google Drive UI
But created files and directories are still not visible in Google Drive UI
Please connect with the account you want to display on GoogleDrive UI by OAuth authentication.
@nao-pon I've used this way and got the following error:
[Google_Service_Exception]
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
Sam me