Search code examples
phpziparchivepharscandir

Phar:// stream wrapper with space in the filename


so I have a zip file in directory

/pathdodir/the zip file.zip

so I do this:

$dir = 'phar:///pathdodir/the zip file.zip';
$file = scandir($dir);
print_r($file);

but then this ends up complaining about

"failed to open dir: phar error: invalid url or non-existent phar"

if I rename the zip file such that it has without spaces though ie to thezipfile.zip and then change $dir to thezipfile.zip as well, phar would work and it would print_r the files inside that zip accordingly...

how do I make it so that phar would also work even if there are spaces in the filename?


Solution

  • The file name you use - phar:///pathdodir/the zip file.zip - is an URL; it has a schema (phar://).

    You have to url-encode special characters in URLs, and the space is encoded as %20.