Some Help Please

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
bawla
Forum Contributor
Posts: 116
Joined: Fri Mar 19, 2004 9:15 am

Some Help Please

Post by bawla »

One thing I need to change about this script is to make the filename a link so people can download them, and after the file size I need it to say bytes.
Thats basically it, not very hard but I dont know very much just need some quick assistance.

Code: Select all

<?php
echo "<table border='1' bordercolor='#D2D2D2' cellpadding='1' cellspacing='1' width='100%'>";
// Ensure $dir has a trailing backslash
$dir = 'music/Alternative/';
$opened = opendir($dir);
while( false !== ($file = readdir($opened))) {
 if($file != "." && $file != ".." && !is_dir($file)) {
  $type = filetype($dir.$file);
  $size = filesize($dir.$file);
  $store[$file] = array($file,$size,$type);
 }
}
closedir($opened);
asort($store);
foreach($store as $key => $value) {
echo "<tr><td width='50%'>{$value[0]}</td><td width='20%'>{$value[1]}</td><td width='30%'>{$value[2]}</td></tr>";
}
echo "</table>";
exit();
?>
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

untested

Code: Select all

<?php
echo "<table border='1' bordercolor='#D2D2D2' cellpadding='1' cellspacing='1' width='100%'>";
// Ensure $dir has a trailing backslash
$dir = 'music/Alternative/';
$opened = opendir($dir);
while( false !== ($file = readdir($opened))) {
if($file != "." && $file != ".." && !is_dir($file)) {
  $type = filetype($dir.$file);
  $size = filesize($dir.$file);
  $store[$file] = array($file,$size,$type);
}
}
closedir($opened);
asort($store);
foreach($store as $key => $value) {
echo "<tr><td width='50%'><a href="{$dir}{$value[0]}">{$value[0]}</a></td><td width='20%'>{$value[1]} bytes</td><td width='30%'>{$value[2]}</td></tr>";
}
echo "</table>";
exit();
?>
note: This is a basic version, and isn't secure... you should probably create an anti-leeching file downloader.. search the forums for "file download" or read: [php_man]header[/php_man]()
Post Reply