0

So, I am trying to check if a file exists in a tar.gz file. I have tried using

fopen('phar://path');

But the issue is, it exceeds the Allowed memory size. What I am trying to do is identify if the tar.gz file contains a database dump. One way to solve this issue is add db in the name of the tar file at the time of creation. But is there a way to check if the file exists, without exceeding the Memory limit, As the tar file can be up to few GB's

Vardana Bhanot
  • 94
  • 2
  • 11
  • Seems similar to this: [How to get content of a single text or a single json file inside a .tar.gz file in PHP?](https://stackoverflow.com/questions/38337107/how-to-get-content-of-a-single-text-or-a-single-json-file-inside-a-tar-gz-file). I would create a background process that has more resources and unzips, then writes the filenames / metadata contained to a cache (database or otherwise). – Peter Krebs Feb 07 '23 at 14:03

1 Answers1

1

This will generate you an array of contents, all you would have to do is search the array $output for the filename you are interested in.

$filename = "stuff/my.tar.gz";

$output = [];
$result_code = '';

exec("tar -tf " . $filename, $output, $result_code);

echo $result_code;
print_r($output);
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149