note 29704 deleted from ref.dir by didou

From: Date: Thu, 29 May 2003 22:20:38 +0000
Subject: note 29704 deleted from ref.dir by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-49349@lists.php.net to get a copy of this message
Note Submitter: admin@csmapcentral.com ---- tlsprwr at hotmail dot com made some code corrections, but since he hadn't tried his corrections, he didn't realize that he was trying to divide the variable $path by $file e.g.- ($path/$file)/1024 i corrected this by chging his code to ($path.$file)/1024 here's my version of the code with a couple of additions (a new variable and an if statement in case a user is using the relative path): $base_dir='/var/www/html/files/'; //define the path as relative //$path = "."; //$base_dir is a variable i created that contains the non-relative dir path $path = $base_dir; //using the opendir function $dir_handle = @opendir($path) or die("Unable to open $path"); //make string with 70 spaces $space=" "; echo "<PRE>"; echo "Directory Listing of $path\n"; //running the while loop if ($path != "."){ while ($file = readdir($dir_handle)) { // filename - output left-justified $t="<a href=$path/$file>$file</a>"; echo $t.substr($space,0,40-strlen($file)) ; // filesize - output right-justified $t=(filesize($path.$file)/1024); $t=sprintf("%01.2f",$t)."kb "; echo substr($space,0,10-strlen($t)) . $t ; // filedate - output left-justified $t=date("d.M Y H:i:s", filemtime($path.$file)); echo $t.substr($space,0,20-strlen($file)) ; echo "\n"; } } elseif ($path = ".") { while ($file = readdir($dir_handle)) { // filename - output left-justified $t="<a href=$file>$file</a>"; echo $t.substr($space,0,40-strlen($file)) ; // filesize - output right-justified $t=(filesize($file)/1024); $t=sprintf("%01.2f",$t)."kb "; echo substr($space,0,10-strlen($t)) . $t ; // filedate - output left-justified $t=date("d.M Y H:i:s", filemtime($file)); echo $t.substr($space,0,20-strlen($file)) ; echo "\n"; } } //closing the directory closedir($dir_handle); echo "</PRE>";

« previous php.notes (#49349) next »