Archive for December, 2012

Cheat Sheet

Posted: December 22, 2012 in Php



Save photos in a folder named as ‘images’ and use these scripts to display all photos in a fly.

Display Images From A Folder

$files = glob("images/*.*");
for ($i=1; $i<count($files); $i++)
	$num = $files[$i];
	echo '<img src="'.$num.'" alt="random image">'."&nbsp;&nbsp;";

Display Images With Image Name From A Folder

$files = glob("images/*.*");
for ($i=1; $i<count($files); $i++)
	$num = $files[$i];
	print $num."<br />";
	echo '<img src="'.$num.'" alt="random image" />'."<br /><br />";

Display Images From Folder Script Download


Allow Editor/user to Edit Theme options MENU
you can add capabilities to the editor role using the role object and add_cap from you functions.php

Place the following code in functions.php

   // get the the role object
   $editor = get_role('editor');
   // add $cap capability to this role object

you can also remove capabilities:


just take a look at the list of capabilities and what each one means.

UNZIP Files On Your Server

Posted: December 11, 2012 in Php

A Few Questions First

How often do you FTP a new wordpress install to your live server?
Well if you are a freelance web designer or developer then I would say quite often. Every time you put a new site live you have to upload the entire wordpress site which can be 800+ files.

How long does it you take to upload your whole wordpress site?
The last time I timed it (with a fresh install of wordpress 3 beta 1), it took over 10 minutes to upload the 815 files (10.7 MB).

Why does it take so long?
Besides my really slow internet connection, it’s really FTP’s fault. Depending on the software you use (I use FileZilla), you can choose how many concurrent transfers, but when you are uploading 800+ files, being able to transfer 10 files at once still can take a while. Also, the file size is a factor and the fact that most of the files being transferred are php files means that there is major room for improvement from a compression point of view.

The Obvious Next Step – ZIP

Obviously we need to compress the files into a single zip archive. We could then upload the much smaller file to the server. The only problem left is that we need to unzip the file once it has been uploaded onto the server. And one way to do that would be to write some PHP code to do this task for us. But since you are reading this article in order to save time, I am guessing you don’t have time to write this code either.

The Solution

PHP UnZIP comes to the party and fills this gap. It allows you to FTP your much smaller zip file onto your server and then unzip it in 1 click. All the logic is contained in a single file ‘unzip.php’ which weighs in at 98KB. So all we need to do is FTP our zip archive together with the unzip.php file and we can do exactly what we have set out to.

Step By Step

  1. Download and extract unzip.php.
  2. Zip your wordpress install (or whatever else) into a single zip.
  3. Upload your new zip together with unzip.php to your server via FTP. Make sure the zip file is in the correct directory on your server where you would like it to be extracted.
  4. CHMOD unzip.php to 777. I do this with my FTP program (FileZilla) by right-clicking on the file and selecting ‘File Permissions’. (for windows you will have to allow full control or modify secutiry permission to the necessary user)
  5. Open the file unzip.php in your browser.
  6. Browse your server’s directories and click the zip file to UnZIP it!
  7. Delete both the zip file and unzip.php.
  8. Decide what to do with the extra time you now have.

Comparison Of Before And After

Before After
File Count 815 2
File Size 10.7 MB 3.2 MB
Time Taken 14 mins 2 mins

UnZIP In Action

UnZip screen shot 1
UnZip screenshot 2

Tools Used


You can now upload your entire WordPress website to your server in a quarter of the time or less using UnZIP. I hope you find this useful, and please let us know what you think or if there are ways to improve it.

Download here :