1

我在托管在 Google App Engine 上的应用程序中使用了 glob() 函数,而我的 text_files 在 Google Cloud Storage 上。它不起作用并返回false。这是代码:

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

我在 GCS 上的文件是这样的:

textfile_Ben.txt
textfile_Sam.txt
textfile_David.txt

我检查了http://php.net/manual/en/function.glob.php它说:

注意:此功能不适用于远程文件,因为要检查的文件必须可以通过服务器的文件系统访问。

我的应用程序可以与其他功能(例如file_get_contents()file_put_contents().

问题:是否有任何使用glob()功能的解决方案,或者是否有任何替代方法来执行相同的功能?

4

2 回答 2

2

使用 opendir/readdir 并自己过滤路径。

于 2013-10-05T09:35:53.287 回答
1

我有解决方案:)

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

干杯

于 2013-10-15T15:34:50.783 回答