rkrause54 Posted August 29, 2013 Share Posted August 29, 2013 Hello, I am looking for help in revising this script to accept tar.gz & zip files for unzipping. This script is being used in an FTP command and currently works for zip files just not tar.gz files. I tried simply substituting tar.gz in the places where $zip is shown but that failed. <?php $zip = new ZipArchive;$res = $zip->open("");if ($res == TRUE) {$zip->extractTo("/");$zip->close();echo "unzip ok";} else {echo "unzip failed";}?> Any help would be appreciated. Thanks,Ryan. Link to comment https://forums.phpfreaks.com/topic/281676-php-unzip-compressed-file-and-unzip-targz-file/ Share on other sites More sharing options...
AbraCadaver Posted August 29, 2013 Share Posted August 29, 2013 If you have a recent PHP version and zlib compression enabled the use PharData or the Phar class or use the command if you're on Linux: exec('tar zxf /path/to/file.tar.gz'); Link to comment https://forums.phpfreaks.com/topic/281676-php-unzip-compressed-file-and-unzip-targz-file/#findComment-1447364 Share on other sites More sharing options...
rkrause54 Posted August 30, 2013 Author Share Posted August 30, 2013 Thanks for the help.Is there a way to run one .php file that will work for either option? Currently, i'm using 2 different php scripts and don't know how to combine them into one so it will extract a tar.gz or a .zip. Ryan. Link to comment https://forums.phpfreaks.com/topic/281676-php-unzip-compressed-file-and-unzip-targz-file/#findComment-1447484 Share on other sites More sharing options...
jazzman1 Posted August 31, 2013 Share Posted August 31, 2013 Create a function that searches all archive files into this directory. Then make comparison. If the file extension is "tar.gz" use one method if a "zip" other. It's simple! Link to comment https://forums.phpfreaks.com/topic/281676-php-unzip-compressed-file-and-unzip-targz-file/#findComment-1447579 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.