I'm trying to read a file content from a zip file with ZipArchive with the method getFromName. My file name has a double dot in it (..
). Here's my code:
$zip = new ZipArchive();
$zip->open('book.zip');
$content = $zip->getFromName('book/html/../README.md');
var_dump($content);
The structure of my zip file is this:
Archive: book.zip
Length Date Time Name
--------- ---------- ----- ----
0 2016-06-01 11:09 book/
0 2016-06-01 11:02 book/html/
1855 2016-06-01 11:02 book/html/composer.json
2354 2016-06-01 11:09 book/README.md
--------- -------
4209 4 files
My PHP script is in the same directory as my zip file. When I try to list the file in the folder that I have zipped with Linux command like this:
ls -l book/html/../README.md
It works perfectly. I don't understand why ZipArchive can't read this relative path correctly.
Note: I know that I can read the file with the absolute path: book/README.md
but I really need to use the relative path with ..
because the file paths are loaded dynamically from another place and I don't have a control on them.