Is it possible to open a ZIP file on a server, read a file from its content and display it / send it to a client directly without extracting it to disk first ? I am talking about pdf's
and images
. Haven't found any hints in the php sites.
Asked
Active
Viewed 290 times
1

Ben
- 677
- 5
- 19
-
What platform are you trying to develop in? – Shaurya Chaudhuri Oct 20 '16 at 17:25
-
sorry I forgot - Linux , Apache, PHP – Ben Oct 20 '16 at 17:28
-
Possible duplicate of [How to read a single file inside a zip archive](http://stackoverflow.com/questions/10420112/how-to-read-a-single-file-inside-a-zip-archive) – cmorrissey Oct 20 '16 at 17:30
1 Answers
1
Well,there is a PHP Extension. If you use the extractTo method, you would be able to extract a single file, checkout the documentation.
From the documentation, extracting two files:-
<?php
$zip = new ZipArchive;
$res = $zip->open('test_im.zip');
if ($res === TRUE) {
$zip->extractTo('/my/destination/dir/', array('pear_item.gif', 'testfromfile.php'));
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>
You would need to provide an array of path inside the zip.

Shaurya Chaudhuri
- 3,772
- 6
- 28
- 58
-
not quite right - if you only want a single file then just the filename and/or path not an array. You supply an array if you are extracting multiple files I believe. So, $zip->extractTo('/my/destination/dir/', 'pear_item.gif'); if you only want pear_item.gif. – l0ckm4 Oct 31 '19 at 09:39