Coupons and Promo Codes Hosting Tips & Deals

DreamHost Promo Invitations – $100 Off!

DreamHost just gave me 5 promo invitations that could be used for new accounts only. Whoever uses one of the invitation codes to sign up with them would get $100 off for a two-year plan.

Just use one of the 12-digit invitation code in the “Promo Code” field when signing up at DreamHost:

  • 737871080684
  • 599411300419
  • 843524772888
  • 995826163955
  • 163012137693

Each code can only be claimed ONCE and after it is claimed it’s gone forever. Here are some more promo codes for DreamHost:

PHP Tips & Tutorials

PHP: Display Files and Sub-directories of A Directory Recursively as A Tree

Given a directory, how to display the contents (directories and files under it) of it recursively and exhaustively? Here’s the code:

$dir = '/path/to/directory'; // without trailing slash, can be absolute paths such as '/home/jim/public_html' or relative paths such as 'samples'


function getDirContents($dir) {
	if (is_dir($dir)) {
		$dirs = explode('/', $dir);
		$last_dir = $dirs[count($dirs) - 1];
		echo '<strong>'.$last_dir.'</strong>';
	    if ($dh = opendir($dir)) {
	    	echo '<ul>';
	        while (($file = readdir($dh)) !== false) {
	        	if ($file == '.' || $file == '..') {} else {
		        	echo '<li>';
		        	if (is_dir($dir.'/'.$file)) {
		        	} else {
		        		echo $file;
		        	echo '</li>';
	        echo '</ul>';
	return false;

Recursively, the function getDirContents() explores every entry in the directory. If the entry is a file, it simply prints it; if it is a directory, it opens another subroutine of itself to explore that directory; and so forth, until every branch and sub-branches, etc. are all printed out.