Hello,
With the code below, I list the subfolders and files in the source folder with echo. However, I can’t get this list out as an array. What am I doing wrong? Can you help me?
<?php
$copy_from_id = '1ayLi94BVtYHvzmbBXmmW3siQrwiJOotc';
function listFiles($service, $folderId, $path = ''): array
{
$results = $service->files->listFiles([
'orderBy' => "name",
'q' => "'$folderId' in parents",
]);
$list_array = [];
foreach ($results->getFiles() as $file) {
$filePath = $path . '/' . $file->getName();
echo $filePath."<br />";
$list_array[$file->getId()] = $filePath;
if ($file->mimeType == 'application/vnd.google-apps.folder') {
listFiles($service, $file->getId(), $filePath);
}
}
return $list_array;
}
$list_array = listFiles($service, $copy_from_id);
echo '<pre>' . print_r($list_array, true) . '</pre>';
?>
list with echo
/aaaaaaaa
/aaaaaaaa.zip
/bbbbbbb
/bbbbbbb.zip
/zaman
/zaman/bir_alt_zaman
/zaman/bir_alt_zaman/ddddddd.zip
/zaman/bir_alt_zaman/iki_alt_zaman
/zaman/bir_alt_zaman/iki_alt_zaman/web1
/zaman/bir_alt_zaman/iki_alt_zaman/web1/web1.zip
/zaman/bir_alt_zaman/iki_alt_zaman/web2
/zaman/bir_alt_zaman/iki_alt_zaman/web2/web2.zip
/zaman/bir_alt_zaman/iki_alt_zaman/web3
/zaman/bir_alt_zaman/iki_alt_zaman/web3/web3.zip
/zaman/bir_alt_zaman/iki_alt_zaman/web4
/zaman/bir_alt_zaman/iki_alt_zaman/web4/web4.zip
/zaman/bir_alt_zaman/iki_alt_zaman/web5
/zaman/bir_alt_zaman/iki_alt_zaman/web5/web5.zip
/zaman/bir_alt_zaman/iki_alt_zaman/webler.zip
/zaman/cccccccc.zip
The result I got with the array
Array
(
[1Ck1AqWEX832hDd90sNmjyvddl5RzyEtv] => /aaaaaaaa
[1Q7qj_Kx5cIsPxWnmLLRnPC5CamkArFPD] => /aaaaaaaa.zip
[1bJLje66HuCmMhLfbL91M8a59GsxgMe9Y] => /bbbbbbb
[1o5VJqxv8z_IVaCP7PqPrU3VB4k7PSUlL] => /bbbbbbb.zip
[1qalXTD6R2JTIgNy98IGB6spf7lwC8x9K] => /zaman
)