ZipArchive php Class - Is it built-in to PHP? - 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??

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...

Related

Creating a PHP extension extending another PHP extension?

I searched over the Internet several documentation about how to create PHP extensions, but unfortunately, there is nothing about linking to another extensions (and making a requirement for having that extension loaded prior to the new it is being created).
I guess I could simply #include necessary header files into my source code, but not sure about linking.
As an example, and to play with extension creation, the first I want to create is a solution I implemented to allow namespaces in memcached github but wanted to know how to use other extensions' code from my custom extension one for other usages as well.
I'm not sure how to reply to the thread with StormByte, but it sounds like you need to do some load balancing or caching, not extending PHP.
If you really want to do this at the code level, you could use exec() to call a Python script, which gets compiled into byte code automatically.

Fully OO Ftp library for php

I was trying to build an application that will download some files from various ftp servers to a local directory. Later I would upload them to other ftp servers.
The application is built using Zend framework.
The thing is I can't find a class to handle ftp download/upload functions in Zend framework.
The only class available is Zend_File_Transfer which has the following comment:
Note: Limitation
The current implementation of Zend_File_Transfer is
limited to HTTP Post Uploads. Other adapters supporting downloads and
other protocols will be added in future releases. Unimplemented
methods will throw an exception. For now, you should use
Zend_File_Transfer_Adapter_Http directly. As soon as there are
multiple adapters available you can use a common interface.
I need to be able to do the following:
Upload multiple files.
Get a remote directory listing of all files.
Set validators
Set filters
Set paths
Rename files
Wrapper for downloads
Exceptions for various errors during operation.
Is there a solution to this problem in Zend framework? Could you recommend an alternative library for ftp operations ?
Thanks in advance
UPDATE:
I checked the PEAR package and unfortunately it's still in alpha
release. Moreover their functions return errors not exception once a
problem occur like download failure or remote path weren't found.
Unfortunately Skjb_Ftp isn't complete as many functions don't have an implementation.
Check out this php5 wrapper for the builtin FTP functions: https://github.com/dg/ftp-php it has some exception handling stuff you might be able to use.
This is a fully OOP php ftp library i build it in my self (hard working), its unit tested and it will works for your purposes perfectly. php-ftp-client
Here is great library for it: https://github.com/Nicolab/php-ftp-client
There is a proposal for Zend_Ftp that you might be able to use. Failing that, there is Skjb_Ftp.
I cannot vouch for the completeness or validity of either of these solutions, as I haven't used either, but it should be something to get you started. Some of the functionality you require is missing, but it shouldn't be too difficult to add it using the FTP functions.

How popular is PHP Zip Extension?

How popular is PHP ZIP extension by hosting providers? Can I use it as default archive software for my WordPress plugin or should I take a look at another lib?
It's probably easiest if you test for the existence of the extension in your scripts, and use your alternative if Ziparchive doesn't exist. I use a wrapper class that checks whether the class is present, and switches to using pclzip (which is included in my library distribution) if not... but all the calls are made to the wrapper to pass on to ZipArchive or PCLZip as appropriate.

c++ php and static library

I've created a library.a that contains a .cpp and .h files with a lot of classes, nested classes and methods. I would like to include this static library inside a php example and try to work with it. I would like to mention that I am new to php. I've tested my libray.a inside a test.cpp file and it works. How can I create a test.php and test my library.a?If it;s possible please send me some examples.
I would like to mention that i am working in ubuntu. g++ was my compiler.
Thx for advices! Appreciate!
EDIT:
I WOULD LIKE TO MENTION THE FACT THAT I DON'T WANT TO EXPOSE MY .CPP CODE. I JUST WANT TO USE MY .H AND .A FILES.
An .a file is not a self-executable library. It is static object code. It cannot run by itself.
PHP doesn't have loaders. It can't load a .a file, neither your very own operating system can.
An .a file needs to be accompanied by the appropriate headers (.h files).
If you want to use native code within PHP, you must use PHP's interfaces. See, just like anything built with C/C++, PHP has it's own definition of what a string (or most data types) look like.
In short, you have two options:
use PHP's headers and interface your code directly with PHP
use a library wrapper which connects your calls to PHP
make your library into an executable and call it with PHP*
*PHP has plenty IPC methods, so this is actually quite feasible.

Libraries other than ZipArchive for creating pkzip archives in PHP?

I'm in the process of writing some epub creation functionality using php5. Currently I am attempting to use ZipArchive but have run into a couple annoyances with it. First of all, there is no functionality to set the compression level. Second of all, ZipArchive::addFile() seems to fail silently and create a corrupt archive whenever I use it. I have been using file_get_contents() + ZipArchive::addFromString() instead but would prefer to just use the documented function for adding files.
I will not post code samples unless someone would really like to help me debug this issue, but rather I'm wondering if there are any other libraries for creating zip (pkzip) archives in PHP that you would recommend. So far, I have seen PclZip, whose site does not seem to be loading, but not much else. I have also considered using exec() + zip (unix command). This code will only run on this one particular linux box so portability is not an issue.
Thanks in advance for any suggestions!
PCLZip is pretty good alternative, with zlib as its only dependency, if you can get access to the site. It's probably temporary, it was certainly accessible between Christmas and New Year.
It's also pretty efficient, even in comparison with ZipArchive
EDIT
You say that you've had problems with ZipArchive's addFile() method. Is this in a Windows environment, or on your Linux server? I know that there have been a few buggy releases of the php_zip library on Win32 that can give this problem, although the latest versions seem OK, and I've not encountered the same problem on other platforms (even the WIN64 version).
I'd use exec() and the Unix command. A native-to-the-system way to solve the problem - the unix utils will always be a step or two ahead from their PEAR counterparts.

Categories