【问题标题】:Google App Engine(php): glob() functionGoogle App Engine(php):glob() 函数
【发布时间】:2013-10-05 02:28:49
【问题描述】:

我在托管在 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() 函数的解决方案,或者有没有其他方法可以实现相同的功能?

【问题讨论】:

标签: php google-app-engine


【解决方案1】:

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

【讨论】:

  • 这是我认为的唯一方法。唯一的问题是它不适用于子目录。我只能使用opendir("gs://bucket_name/") 它不适用于opendir("gs://bucket_name/folder/")
  • 你应该可以打开一个子文件夹。如果它不起作用,您可以在跟踪器中打开问题吗?
  • 不知道你说的“在跟踪器中打开问题”是什么意思 跟踪器在哪里?
【解决方案2】:

我已经找到了解决方案:)

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

干杯

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-10
    • 2015-05-15
    • 2013-07-02
    • 2013-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多