I am trying to ultimately extract some files from a tar archive within PHP, however my simple test script is failing at the first part, which was to simply list the files in the archive.
Is there any reason why this test script fails?
What I see output is:
> -sh-3.2$ php showfile.php /var/www/vhosts/smartphonesoft.com/httpdocs/fred/epf/itunes20100825.tbz
> tar: Old option `f' requires an
> argument. Try `tar --help' or `tar
> --usage' for more information.
My simple PHP script is:
<?php
foreach (glob("/var/www/vhosts/smartphonesoft.com/httpdocs/fred/epf/itunes*.tbz") as $file) {
}
$path_parts = pathinfo($file);
$tarfile = $path_parts['filename'];
echo $file . "\n";
exec('tar tvf $file',$ret);
?>
you have badly placen the parenthesis, ({ }), and bad quotes inside the exec() function:
?>
(using ‘ quotes does NOT substitute the variable
$fileinside the string for the file you meant.)EDIT: according to Frxstrem’s comment, never forget to escape the filename (in case it contains for example spaces, the above code won’t work).