1

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?

Behnam Rasooli
  • 712
  • 5
  • 20
  • 1
    glob won't work with a url, only file system paths. This answer might help http://stackoverflow.com/questions/6997887/glob-not-giving-me-any-results – abstr Oct 05 '13 at 02:52

2 Answers2

2

Use opendir/readdir and filter the paths yourself.

Stuart Langley
  • 7,044
  • 1
  • 20
  • 20
1

I have got the solution :)

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

cheers

W.g.
  • 51
  • 3