FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Need some php help.





hobbes
Here is some code I use on my site, it displays the directories and files in thoses directories and makes them avaliable for download. What I want to do is make it so it does not display .php files. Can any one help me? Here is the code

Code:
function human_file_size($size)
{
   $filesizename = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
   return round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $filesizename[$i];
}

$filelist = array();
$incme = array();
if ($handle = opendir('.')) {
   echo "<ul>";
    while (false !== ($file = readdir($handle))) {
   
      if (is_dir("$file")==True) {
         if ($file ==".") {
            //ignore it
         }elseif ($file =="..") {
            echo "<li><a href='".$file."'><img border=\"$0\" src=\"$CFG->imgdir/folder.gif\"/>...</a></li>";
         } else {
            echo "<li><a href='".$file."'><img border=\"$0\" src=\"$CFG->imgdir/folder.gif\"/> ".$file."</a></li>";
         }
      } else {
         // it's a file
         $temp = explode(".", $file);
         $name = $temp[0];
         $type = $temp[1];
         if ($file=="index.php") {
            // Ignore that too.
         } elseif ($type == "php") {
            array_push($incme, $file);
         } else {
            $file_string = "<li>Download: <a href='".$file."'> ".$file."</a> (".human_file_size(filesize($file)).") <a href='".$file.".htm'>click here for a description</a></li>";
            array_push($filelist, $file_string);
            //echo "<li>Get file: <a href='".$file."'> ".$file."</a> (".human_file_size(filesize($file)).")</li>";
         }
      }
    }
   
    sort($filelist);
    foreach($filelist as $item) {
      echo $item;
   }   
   
   
   echo "</ul>";   
   foreach($incme as $fileto) {
      include_once($fileto);
   }
}
holadola
It seems that you try to execute all php-scripts after the file-listing. Is this what you want to do?
Stubru Freak
Change these lines:

Quote:
Code:
if ($file ==".") {
            //ignore it


Into:

Code:
if ($file =="." || strtolower(array_pop(explode(".", $file))) == "php") {
            //ignore it
Related topics
Mysql And PHP HELP PLZ
Great php editor
PHP Help Needed
need php help save command
mysql/php help please
How to start using PHP? Help!
PHP Help
php HELP!!!
PHP Help Forum
PHP Help please
Php help
php help
PHP HELP
HTML/PHP Help (Contact Box)
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.