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.
Abhinav Singh has posted a guide to PHP extensions - what they are and how to write a simple "hello world" one.
Assuming you have read the previous post, lets discuss on how to build our first PHP extension: every PHP extension is built out of minimum of 2 files, a configuration file (config.m4) which tells us what files to build and what external libraries are needed and source File(s) which will contain the actual functionality.
He builds up an example skeleton for an extension (the config.m4) and explains how the file will be phpized and configured. Next up is the php_sample.h header file where the needed modules are loaded and the sample.c file to define them. Last, but not least, comes the extension code itself that calls the printf function to output the "hello world" message.
In this new blog entryMarc Gear suggests a few things that you can do to help learn a new framework quickly and easily:
There are dozens of PHP frameworks around now, some attracting more attention than others. I am no expert on these frameworks and have not used a single one extensively so I wouldn't dream of recommending one over the other, nor do I want to enter the debate about what is or is not a framework (I'll work on the assumption that anything calling itself a framework is a framework). Instead I'm going to concentrate on how you can get started with a new framework as quickly as possible.
He suggests four examples that can help you get more familiar with each framework and how they're structured - a "hello world" as a first step, creating a simple calculator, making a guestbook and making a simple script to parse and paginate a remote RSS feed.
On the SitePoint PHP blog today Troels Knak-Nielsen has posted about a lesser known feature of the popular XDebug debugging tool - function traces.
In case you haven't heard of it before, it "allows you to log all function calls, including parameters and return values to a file", to quote the manual. After playing around with it for a while, I realised that this information could be parsed and used to determine parameter types and return types of functions.
To illustrate one use for the trace results, he create a simple script that parsed them and reinjected them back into a source file as docblock comments. Included in the post is an example of its usage and the resulting comments for a simple class. It can be downloaded from github.
The TotalPHP site is recommending something that can make your development (and maintenance) life much easier in the long run - using a global configuration file through out your app.
t's one of the basics of PHP and if you read any kind of tutorial or book on the subject it's one of the first things they cover, yet I still see people no using a global 'configuration' or 'include' file. It's one of the easiest things to do and will make your life so much easier! This 'configuration' file will include anything that needs to be run on every page of the website.
They suggest that using this configuration file everywhere (including it over the entire site) can make things easier in the long run. The idea is not without problems, though. It only works until you need something custom for a certain area or page - then you have to hack it to evaluate conditions. For most simple uses, though, its a good way to share information (like database connection details) through out the application.
Laknath Semage submitted a new blog post he's written up about working with large file uploads in your PHP applications.
If we want to do large file uploads or database updates with PHP there are few configurations to be done to default settings and I'm putting this as a note to myself (I'm always keep forgetting this) as well as to any one who may find this useful like when importing a large backup file through phpMyAdmin.
There's four php.ini settings he recommends checking as well as two values to change if you do have the need to upload a large import file back into a phpMyAdmin installation (ExecTimeLimit, MemoryLimit).
With the recent released of the 1.7 version of the Zend FrameworkRob Allen wanted to post about a new form element type that integrates some much needed functionality - Zen_Form_Element_File.
Now that Zend Framework 1.7 has been released, I thought I'd take a look at the built in file upload element, Zend_Form_Element_File, and see how it can be used. This is how to use it in its most basic form.
The form in this example is similar to his previous example and the simple code is included for the form, the controller and the view.
That's all there is to it for simple uploading of forms. There are still a few fairly important bugs in the component that we'll have to wait for 1.7.2 for. Specifically the Count validator doesn't always work as you'd expect and don't use getValues() and receive() as it isn't yet clever enough to know not to call move_uploaded_file() more than once.
Kevin Waterson has posted a new tutorial today looking at a key part of any web application - the configuration settings and how they can be stored.
PHP applications come in many shapes and sizes. Some used locally from command line, and more commonly, for web based applications. More often than not, regardless of size or type, some form of configuration variables will be stored for global access. [...] Each options has its pros and cons. Here each of these options is explored to see which method is right for your application.
He looks at four different options:
an ini file that can be parsed/modified directly by PHP
an XML file slightly more complex, but still simple for PHP to use
a PHP file with things like PHP arrays defining settings
and a database with one or more configuration tables
Each type comes with some example code and format to give you an idea of how they'd work.
Jeremy Johnstone has come up with a simple plist xml parser. The plist format is what iTunes (and some other application) uses for its library files.
Normally SimpleXML is enough to handle most XMLparsing needs, but the plistXML format is just broken enough to make parsing it with SimpleXML virtually impossible. Since I hadn't played with XMLReader much, I thought it would be a good chance to give it a spin. For the anxious types, the code is available on github in my php_class_lib project, so dig right in.
His parser takes in the name of the file to fetch and a parser() method is called to do the actual work. The contents of the file are returned as an array (he includes a print_r() of that output too).
The NETTUTS.com site has a new article pointing out a screecast talking about pulling in and parsing the contents of an RSS feed.
Dynamically pulling in an RSS feed was beyond the scope [of this article]. In today's video tutorial, I'll show you exactly how to do this using PHP. At roughly forty-five minutes in length, you might want to take a quick "pre-screencast bathroom break". You also might want to grab some raisins.
Due to some video issues, the screencast is current posted here (but will be in the post in the future). As always, the source code can be downloaded and a live demo is available to sample the end result.