Jump to content


Photo

Count # of files


  • Please log in to reply
5 replies to this topic

#1 DeathRay2K

DeathRay2K
  • Members
  • 96 posts
  • Location:Canada
  • Projects:D2K Studios, Xaeon Mod, Unseen Presence, Rhythm Mixer, Website Designs, CSS OS

Posted 26 November 2005 - 10:12 PM

I'm trying to find a way to count the number of files in a directory and display their filenames. So far I've only been able to find a way to count the number of files in the directory containing the php file, but that's not what I want...
Any help would be greatly appreciated, and the simpler the script needed the better.

#2 Blodo

Blodo

    The one who disagrees

  • Project Team
  • 3,002 posts
  • Location:Eastern Europe
  • Projects:siteMeister, Mental Omega
  •  The wise guy

Posted 26 November 2005 - 10:48 PM

http://pl2.php.net/m...n.ftp-nlist.php

FTP functions prove really useful here. The example on the site shows how to get the contents of the directory the file is in, to let the file be able to have a directory specified you must use something like this:
<?php

$dir_name = "your directory path on the server";

$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
$contents = ftp_nlist($conn_id, $dir_name);

var_dump($contents);

?>

ARGUMENT FROM CREATION, a.k.a. ARGUMENT FROM PERSONAL INCREDULITY (I)
(1) If evolution is false, then creationism is true, and therefore God exists.
(2) Evolution can't be true, since I lack the mental capacity to understand it; moreover, to accept its truth would cause me to be uncomfortable.
(3) Therefore, God exists.


#3 DeathRay2K

DeathRay2K
  • Members
  • 96 posts
  • Location:Canada
  • Projects:D2K Studios, Xaeon Mod, Unseen Presence, Rhythm Mixer, Website Designs, CSS OS

Posted 27 November 2005 - 12:02 AM

Thank you, but now it just shows up as 'NULL'... =/

#4 Mastermind

Mastermind

    Server Technician

  • Undead
  • 7,014 posts
  • Location:Cambridge, MA
  • Projects:MasterNews 3
  •  The Man Behind the Curtain

Posted 27 November 2005 - 12:08 AM

opendir or open_dir is going to be your friend.
:p
Posted Image

Well, when it comes to writing an expository essay about counter-insurgent tactics, I'm of the old school. First you tell them how you're going to kill them. Then you kill them. Then you tell them how you just killed them.

Too cute! | Server Status: If you can read this, it's up |

#5 DeathRay2K

DeathRay2K
  • Members
  • 96 posts
  • Location:Canada
  • Projects:D2K Studios, Xaeon Mod, Unseen Presence, Rhythm Mixer, Website Designs, CSS OS

Posted 27 November 2005 - 01:54 AM

Thank you very much Mastermind!
I got it working amazingly well like so:
 <?php
    if (is_dir($dir)) {
   	 $dh = opendir($dir);
   	 if($dh = opendir($dir)){
      while (($file = readdir($dh)) !== false ) {
     	 $dot = explode('.',$file);
     	 if(is_dir($file) | count($dot)!=2 ){
        $type = 'Directory';}
        else{
        $type = 'File';
     	 echo '<div id="file">' . $file . '<br><div id="download"><a href="?file=' . $file . '">Download</a></div></div><br>';
     	 }
      }
   	 }
   	 closedir($dh);
    }
    else {
    echo 'Directory does not exist';
    }
 	 ?>
  </div>
Which then links it to the code that I got help with before. :p I am exceptionally pleased.

#6 DeathRay2K

DeathRay2K
  • Members
  • 96 posts
  • Location:Canada
  • Projects:D2K Studios, Xaeon Mod, Unseen Presence, Rhythm Mixer, Website Designs, CSS OS

Posted 28 November 2005 - 04:18 AM

Go to http://www.d2kstudio...m/downloads.php to see the fruits of my labour. :sleep: I use the code in this page and my previous post in this forum, as well as a lot extra for displaying categories, and counting files. ^_^ And its purty too. (At least in Firefox) ;)

Edited by DeathRay2K, 28 November 2005 - 04:20 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users