[PHP] Re: How to write a PHP coding to list out all files and directories aslinks to them?

2011-04-28 Thread Mitch

On 4/14/2011 6:16 PM, Mikhail S wrote:

How to write a PHP coding to list out all files and directories as links to
them?

This is somewhat similar to some index pages. When new file or folder is
added to the directory, HTML page should display the newly created
file/folder together with previous ones after it is being refreshed. (prefer
in alphabatical order)

How to achieve this sort of functionality in PHP? Please provide sample
coding as well. (and any references)

Thanks.

--
Mike
http://jp.shopsloop.com/



OK, maybe not the most elegant ... but it works for my purposes ... and 
it was my first attempt at these directory functions. You can navigate 
up and down the directory hierarchy. It flags files older than 1 year 
for potential cleanup.


Hope it gives you some ideas and a place to start...

Mitch
#! /usr/bin/php4
html
head
titleDiskspace Analyzer/title
?php
foreach ($_REQUEST as $key=$value){
$$key = $value;
}
?
/head
body

form name=form1 method=POST action=?php $PHP_SELF ?
  p align=centerfont color=#FF size=+2Enter Directory Name 
Here/font/p
  p align=center 
input name=dName type=text id=dName value=?php $dName ? 
size=50 maxlength=256
input type=submit name=Submit value=Submit
  /p
  /form
br
?php
if (isset($dName)  is_dir($dName)){
print(hr\n);
print(font size=\+2\strong$dName Directory 
Information/strong/fontbrnbsp;\n);
print(font color=\yellow\strongHighlighted/strong/font files 
are older than 1 year and candidates for cleanupbrnbsp;\n);
print(table border=\1\ bordercolor=\gray\ cellspacing=\0\ 
cellpadding=\5\\n);
print(th bgcolor=\black\font color=\white\File 
Name/font/thth bgcolor=\black\font color=\white\File 
Size/font/thth bgcolor=\black\font color=\white\File 
Date/font/th\n);
$d = @dir(trim($dName));
while ($entry = @$d-read()){
$total++;
$fileExt = explode(., $entry);
if(is_dir($d-path . / . $entry)){
if($fileExt[0] ==){
$fileExt[1] = SysDirectories;
} else {
$fileExt[1] = Directories;
}
$dirSize = filesize($d-path . / . $entry);
$totaldirSize += $dirSize;
$dirList[$entry] = $dirSize;
} else {
$fileExt[1] = Files;
$fileStats = @stat($d-path . / . $entry);
$fileSize = $fileStats[7];
$totalSize += $fileSize;
$currDate = getdate();
$fdDay = date(z, $fileStats[10]);
$fdYear = date(Y, $fileStats[10]);
$ckDay = $currDate[yday];
$ckYear = ($currDate[year] - 1);
if (($fdYear  $ckYear) || (($fdYear == $ckYear)  
($fdDay = $ckDay))){
$highlight = yellow;
$totalSavings += $fileStats[7];
} else {
$highlight = white;
}
print(\ttr\n);
print(\t\ttd bgcolor=\$highlight\$entry/tdtd 
bgcolor=\$highlight\ align=\right\$fileSize/tdtd align=\right\ 
bgcolor=\$highlight\);
printf(%s, date(m/d/Y, $fileStats[10]));
print(/td\n);
print(\t/tr\n);
}
$fileTypes[$fileExt[1]]++;
}
print(\ttr\n);
print(\t\ttd bgcolor=\gray\strongTotal Bytes in 
Files/strong/tdtd align=\right\ 
bgcolor=\gray\strong$totalSize/strong/tdtd align=\right\ 
bgcolor=\gray\);
if ($totalSavings  0){
print(strongPotential Savings: $totalSavings/strong);
}
print(/td\n);
print(\t/tr\n);
print(/tablebrnbsp;\n);

if(count($dirList)  1){
ksort($dirList);
print(table border=\1\ bordercolor=\gray\ 
cellspacing=\0\ cellpadding=\5\\n);
print(th bgcolor=\black\font 
color=\white\Directories/font/th\n);
foreach ($dirList as $key=$value){
print(\ttr\n);
if ($key == .){
print(\t\ttd$key nbsp;(Current)/td\n);
} elseif ($key == ..){
$truncPoint = strrpos($dName, /);
$parentDir = substr($dName, 0, $truncPoint);
if ($parentDir == ){
$parentDir = /;
}
print(\t\ttda href=\ . $PHP_SELF . 
?dName= . $parentDir . Submit=Submit\$key/a (Parent)/td\n);
} else {
print(\t\ttda href=\ . 

[PHP] Re: How to write a PHP coding to list out all files and directories aslinks to them?

2011-04-16 Thread Shawn McKenzie
On 04/14/2011 06:16 PM, Mikhail S wrote:
 How to write a PHP coding to list out all files and directories as links to
 them?
 
 This is somewhat similar to some index pages. When new file or folder is
 added to the directory, HTML page should display the newly created
 file/folder together with previous ones after it is being refreshed. (prefer
 in alphabatical order)
 
 How to achieve this sort of functionality in PHP? Please provide sample
 coding as well. (and any references)
 
 Thanks.
 
 --
 Mike
 http://jp.shopsloop.com/
 

I prefer glob().  Give it a shot and ask for help on code that you have
tried.


-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: How to write a PHP coding to list out all files and directories aslinks to them?

2011-04-16 Thread Ashley Sheridan
On Sat, 2011-04-16 at 15:02 -0500, Shawn McKenzie wrote:

 On 04/14/2011 06:16 PM, Mikhail S wrote:
  How to write a PHP coding to list out all files and directories as links to
  them?
  
  This is somewhat similar to some index pages. When new file or folder is
  added to the directory, HTML page should display the newly created
  file/folder together with previous ones after it is being refreshed. (prefer
  in alphabatical order)
  
  How to achieve this sort of functionality in PHP? Please provide sample
  coding as well. (and any references)
  
  Thanks.
  
  --
  Mike
  http://jp.shopsloop.com/
  
 
 I prefer glob().  Give it a shot and ask for help on code that you have
 tried.
 
 
 -- 
 Thanks!
 -Shawn
 http://www.spidean.com
 


There is a setting of Apache that will do this automatically for
directories that have no index, I don't remember exactly what it is
right now, but a quick Google should yield results
-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk