The NETTUTS.com site has a new tutorial/screencast posted looking at their method for opening up uploaded zip files with PHP:
ThemeForest has a nice feature; It allows the authors to upload zip files containing screenshots of their themes. A script then extracts these files and displays the images accordingly. Though I doubt that the developers used PHP to accomplish this task...that's what we're going to use!
They create a simple form with one field - a file input - and write some basic PHP around it. The script ensures that it was a zip file that was uploaded (based on the mime type) and passes it through a ZipArchive class to do the hard work. This class and the rest of the source can be downloaded from the site.
Jani Hartikainen has put together a handy script for those out there that like what the Zend Framework is all about but don't really need the whole thing to get the job done. If that's you, this script might be just what you need.
Did you ever want to use just a single component from Zend Framework, but couldn't figure out which files you needed? Well, here's a solution: Zend Framework packageizer script! Just pick the class you want, and you'll get it and all its dependencies in a nice zip file for you to consume.
The packager uses the tokenizer functionality PHP offers natively to look through the files for the package you're after and finds all of the files that might need to be included and pulls them right along into the zip file.
On his web development blog, Joey has posted a new list of eight handy regular expressions you can use in your code for common validations.
Here are eight examples of practical PHP regular expressions and techniques that I've used over the past few years using Perl Compatible Regular Expressions. This guide goes over the eight different validation techniques and describes briefly how they work. Usernames, telephone numbers, email addresses, and more.
Each of the regular expressions comes complete with an explanation of what it is and the kinds of strings it's looking for. Comments on the post have helped even more, finding places where they might break or not catch all possibilities.
On the Web Development Blog, there's a quick tutorial on creating dynamic zip files via a helpful little class:
For a future project I needed these days some easy to use zip or gzip class to create a zip file from files / folders inside a specified directory. [...] I tested two [other] scripts before and must say that this script works great for single files if you add them manually. To compress a whole directory with an unknown number of files into one zip file I created some class extension to get this job done.
In his class, the get_file_from_folder method is called with the directory and the file to load them into. This loops through the files, pulling them all (directories and all) into the new zip file. An example of the class' use is also included.
Rob Allen has posted about more updates that have been made to his Zend Framework tutorial zip file - one now contains a copy of the framework, the other doesn't.
This time, I've created two files: one with the Zend Framework (1.0.1) included and one without. The one without is much smaller at only 9KB, where as with the Framework, the zip is 2.2MB.
You can download the version with just the tutorial or with the combination directly from his websites. The tutorial has also been bumped up a version (to 1.4.4) with a few updates.
On the JSLabs blog today, there's a (short) new tutorial showing an alternate method to creating a Zip archive in PHP (rather than with the zip extension).
He illustrates the creation of simple archive that pulls in a test file from a given path. This is then pushed into the zip archive and packed down and exported. He also notes the different compression levels that it can be created with - no compression, bzipped and gzipped.
The Zend Developer Zone has a new tutorial that focuses on the dynamic creation of zip archives in a PHP application.
PHP too has included support for the ZIP format since PHP 4.x but it was only recently when, idly browsing the PHP manual, I realized that PHP 5.2.0 includes a re-engineered version of the ext/zip extension, one based on the zlib library. Bored and not a little intrigued, I decided to try it out. And over the next few pages, I'm going to tell you what I found.
The tutorial does require that you have the zip extension installed before getting started. He starts with the basics (reading and opening a zip file) but quickly moves on to creating and decompressing them. All of the code needed is included of course, so you'll be up and working with your own zip files in no time.
There's a recently posted article on the IBM developerWorks website today that's part four in a series they've been doing on what's different in PHP 5.2. This time, they focus on a handy little extension that can really work wonders - the Zip extension.
ZIP? It's about time! PHP just added ZIP features to PHP V5.2. Now they're now built-in. This article, Part 4 of a five-part "What's new in PHP V5.2" series, shows you how to make the most of this new feature by creating, editing, uploading and reading, and creating and downloading ZIP files. After reading this article, you will be well versed in the art of ZIP files using the latest ZIP PHP extension in PHP V5.2, so you can reduce bandwidth overhead or storage usage when handling large files with PHP.
The article is broken up into the four obvious sections:
what is compression?
what's in a zip file?
making a zip archive with PHP
uncompressing a zip archive with PHP
The last two come with their own code examples, using a simple text file to make the archive.
Pierre-Alain Joye has posted about the release of the latest version of his Zip PECL extension - version 1.8.7 - including what it fixes.
Zip-1.8.7 fixes two problems related to open_basedir and safe mode. One was discovered by Stefan Esser (#20 in his mopb) and affects the zip:// stream wrapper. The other is in the open method of the ZipArchive class. I I forgot these two places while applying the php6+ changes and cleaning the code base. I recommend to upgrade as soon as possible.
He notes that, thanks to information from Stefan Esser, this issue was fixed the same day it was posted (the zip:// flaw he mentioned). You can get more information on this package from its PECL homepage or just grab the latest update here.
Pierre-Alain Joye has three different posts to his blog about the releases of new versions (or new software) he (and others) have posted recently - a new release candidate for GD, the new Hidef extension in PECL, and a bug release for the zip extension.
The first post concerns the Zip extension release and which of the provided libraries you should use with your PHP installation (he recommends the latest PECL version over the included version). There's also a link to the new release - 1.8.6
The second post is an announcement about the publishing of the Hidef extension into the PECL library (by Gopal Vijayaraghavan). It can be used to do a "one time declare" of constants in your application, working with a configuration file to only load them the first time the browser hits the site/application.
Finally, in the newest of the posts, Pierre points out a brand new release candidate for GD 2.0.35 to two possible correct race conditions. You can download this new release here: tar.gz file, tar.bz2 file