PHP to read dir and echo zip files as download links with size and date info per table row

Hi,

How can I do the following?

I would like to have a directory read and then each Zip file within to be echoed in a separate row by date order as a download link with file size and file date/time on the same row but in different columns.  

Thanks
sany101Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Roger BaklundCommented:
Try something like this:
$folder = '/path/to/directory';
$dir = dir($folder);
$found = array();
while(false!==($entry=$dir->read())) {
  $path_parts = pathinfo($folder.'/'.$entry);
  if($path_parts['extension'] != 'zip') continue;
  $stats = stat($folder.'/'.$entry);
  $modtime = $stats[9];
  $found[$modtime] = $entry;
}
ksort($found);  # sort by key
echo '<table>';
foreach($found as $modtime => $filename)
  echo '<tr><td>'.$filename.'</td><td>'.
    date('m/d-Y H:i:s',$modtime).'</td></tr>';
echo '</table>';

Open in new window

0
sany101Author Commented:
Perfect thanks cxr,

How can I also add the file size?

Sany



0
Roger BaklundCommented:
Sorry, forgot the size. This should do it:
$folder = '/path/to/directory';
$dir = dir($folder);
$found = array();
while(false!==($entry=$dir->read())) {
  $path_parts = pathinfo($folder.'/'.$entry);
  if($path_parts['extension'] != 'zip') continue;
  $stats = stat($folder.'/'.$entry);
  $modtime = $stats[9];
  $size = $stats[7];
  $found[$modtime] = array($entry,$size);
}
ksort($found);  # sort by key
echo 'count:'.count($found);
echo '<table>';
foreach($found as $modtime => $filedata) {
  list($filename,$size) = $filedata;
  echo '<tr>'.
       '<td>'.$filename.'</td>'.
       '<td align="right">'.$size.'</td>'.
       '<td>'.date('m/d-Y H:i:s',$modtime).'</td>'.
       '</tr>';
}
echo '</table>';

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Roger BaklundCommented:
remove line 13
0
sany101Author Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.