1

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.

Ben
  • 677
  • 5
  • 19

1 Answers1

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