Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ZipArchive php Class - Is it built-in to PHP?

Ok, just wondering on the versions of PHP that this class is built into. And if they are built into all platforms (OS's). I'm wanting an approach to search through a zip file and place files using file_put_contents in different filepaths within the webroot. In any case, I'm familiar with how to do this with the ZipArchive class, but I'm wondering if using this class would be a good solution and support MOST, if not ALL servers?? I mean, I'd rather not use a method that requires the Server to have it installed. I'm looking for a solution to this that will support at least MOST servers without having to install the class...

Thanks :)

Also, I'd like to support opening tar.gz and/or .tgz files if possible, but I don't think the ZipArchive class supports this, but perhaps a different built-in php class does??

like image 755
SoLoGHoST Avatar asked Apr 30 '10 02:04

SoLoGHoST


People also ask

How do I know if ZipArchive is installed in PHP?

You can check whether ZipArchive is installed by using a PHP info file. See an example below: <? php phpinfo(); ?>

How to zip file in PHP?

Place the php files along with the directory to be zipped in C:\xampp\htdocs(XAMPP is installed in C: drive in this case). In the browser, enter https://localhost/zip.php as the url and the file will be zipped. After this a new zip file is created named 'file'.

How to install zip PHP extension?

Home >> Software >> EasyApache 4. You'd then choose to 'Customize' under 'Currently Installed Packages'. From there you can manage PHP extensions to check and ensure that everything your application needs is installed.


1 Answers

Tar support is not built into PHP, but if you have a look at the PEAR library you should be able to find some classes that support creating/extracting tarballs (amongst others). Have a look at http://pear.php.net/package/Archive_Tar or http://pear.php.net/package/File_Archive. The last one should be a generic interface to multiple archiving formats (including ZIP and TAR).

Whether or not ZIP support is built-in may vary, though I guess most packagers will include it. Then again, you could always test it by checking if the ZipArchive class exists by calling class_exists('ZipArchive'); and show a nice error message or fall back to a more generic approach...

like image 69
wimvds Avatar answered Sep 28 '22 09:09

wimvds