Im using a local (rhel 8) server to unzip a file using php (solution proposed in : https://stackoverflow.com/a/8889126/9583635)
<?php
// assuming file.zip is in the same directory as the executing script.
$file = 'temperatures.zip';
// get the absolute path to $file
$path = pathinfo(realpath($file), PATHINFO_DIRNAME);
$zip = new ZipArchive;
$res = $zip->open($file);
if ($res === TRUE) {
// extract it to the path we determined above
$zip->extractTo($path);
$zip->close();
echo "Success! $file extracted to $path";
} else {
echo "Failled! I couldn't open $file";
}
?>
The problem is:
- when I execute this code on the server using:
php /var/www/html/unzip.php
it works fine (success message) and I find the extracted file in the same directory. - but when I use browser (http://192.168.1.5/unzip.php) the success message is printed but I can't find the unziped file in this directory.
note: I tried using wamp server and it works, so the problem may be in the server.