Google App Engine(php): glob() function

2019-08-19 17:37发布

I used glob() function in my application which is hosted on Google App Engine and my text_files are on Google Cloud Storage. It doesn't work and return false. Here is the code:

$links = glob("gs://bucket_name/folder/textfile_*");
if($links){
    echo "true \n";
    print_r($links);
}else{
    echo "false";
}

And my files on GCS are like this:

textfile_Ben.txt
textfile_Sam.txt
textfile_David.txt

I checked the http://php.net/manual/en/function.glob.php and it says:

Note: This function will not work on remote files as the file to be examined must be accessible via the server's filesystem.

My application works fine with other functions such file_get_contents() or file_put_contents().

Question: Is there any solution for using glob() function or is there any alternate method to do the same functionality?

2条回答
一纸荒年 Trace。
2楼-- · 2019-08-19 17:56

I have got the solution :)

$folder = "gs://bucket_name/folder";
foreach (new DirectoryIterator($folder) as $fileInfo)
{
    echo $fileInfo->getFilename();
}

cheers

查看更多
啃猪蹄的小仙女
3楼-- · 2019-08-19 18:09

Use opendir/readdir and filter the paths yourself.

查看更多
登录 后发表回答