Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Getting List Of Directories And Files Using Php, PHP Function for Directory and File List
Corey
post Mar 6 2005, 08:42 AM
Post #1


Super Member
*********

Group: Members
Posts: 218
Joined: 13-January 05
Member No.: 3,267



is there a php function that lists the content of some folder....

example:

/New folder

new.txt
left.gif
download.zip
dc.exe


....so is there..? rolleyes.gif
Go to the top of the page
 
+Quote Post
Ao)K-General
post Mar 6 2005, 12:44 PM
Post #2


Privileged Member
*********

Group: Members
Posts: 524
Joined: 6-March 05
Member No.: 4,187



I have no clue. I think there might be but I dunno. There is something where you can register and the info goes to a folder. But I dunno.
Go to the top of the page
 
+Quote Post
yasir
post Mar 6 2005, 01:49 PM
Post #3


Newbie [Level 1]
*

Group: Members
Posts: 12
Joined: 6-March 05
Member No.: 4,196



best thing would be to Google it!

Try something like 'Advanced PHP Tutorials'

Cheers!
Yasir smile.gif
Go to the top of the page
 
+Quote Post
HmmZ
post Mar 6 2005, 02:14 PM
Post #4


Super Member
*********

Group: Members
Posts: 362
Joined: 2-March 05
From: The Netherlands
Member No.: 4,097



I don't think theres a pre-programmed function for that, you could, of course do it manually, updating it manually when your folder has new content:

CODE
<?php $folder_content = 'echo "The following files are content of the selected folder:"
echo "$list"';
$list= "new.txt, left.gif, download.zip, dc.exe";

echo "$folder_content"; ?>


You could put that in a new file called "folder_content.php" and then (for example in your indexpage, put the following line:

include("folder_content.php");

That way you can easily edit the content it should display manually, while using minimum bytes for your indexpage.

Hope that works for you (im just a newbie phper sad.gif )
Go to the top of the page
 
+Quote Post
bjrn
post Mar 6 2005, 03:13 PM
Post #5


Super Member
*********

Group: Members
Posts: 378
Joined: 8-January 05
Member No.: 3,174



QUOTE(Corey @ Mar 6 2005, 09:42 AM)
is there a php function that lists the content of some folder....

There is opendir() which you can use to open a dir and then loop through the contents.

CODE
<?php
if ($handle = opendir("yourdirhere")) {
 while (($file = readdir($handle)) !== false) {
   echo "filename: $file : filetype: " . filetype($dir . $file) . "\n";
 }
 closedir($dh);
}
?>

Note that this will also list sub-directories and '.' and '..'. You can get info in the php.net documentation for opendir().
Go to the top of the page
 
+Quote Post
mobious
post Mar 7 2005, 11:39 AM
Post #6


Advanced Member
*******

Group: Members
Posts: 113
Joined: 14-January 05
From: Philippines
Member No.: 3,271



i came up with this. it is similar with bjrn's but will sort all folder and files alphabetically. also will be conatined in a multi-dimensional array together with their name and statistics.

CODE

$directory = "path/to/dir";

while (($item = $directory->read()) !== false) {
if ($item != "." && $item != "..") {
 $path = "{$directory->path}/{$item}";
 
 if (is_dir($path)) {
  $tmp['name'] = $item;
  $tmp['stats'] = lstat($path);
 
  $dirs[$item] = $tmp;
 
  unset($tmp);
 } elseif (is_file($path)) {
  $tmp['name'] = $item;
  $tmp['stats'] = lstat($path);
  $tmp['extension'] = substr($item, strrpos($item, "."));
 
  $files[] = $tmp;
 
  unset($tmp);
 }
}
}

ksort($dirs, SORT_STRING);
sort($dirs);

ksort($files, SORT_STRING);
sort($files);
Go to the top of the page
 
+Quote Post
iGuest
post May 13 2008, 06:23 AM
Post #7


Trap Double Mocha Member
***************

Group: Members
Posts: 2,360
Joined: 21-September 07
Member No.: 50,369



Good Php Directory
Getting List Of Directories And Files Using Php

Here is a good PR4 Php directory

Www.Businessservicesuk.Com

-reply by Pete
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Change Permission With Php Code(3)
  2. Script: Php Jukebox(4)
  3. How To Use A Link To Call Function In Php?(8)
  4. Include File.php?id=something(13)
  5. How Good Is This Data Cleaning Function?(2)
  6. Forms, Text Files, And Php For A Signature Generator.(1)
  7. [php]simple Flat File Text Manipulator(3)
  8. Mail() Clone(5)
  9. The Best Zip Function(1)
  10. Unofficial Trap17 Hosted Members Directory(13)
  11. Php Explode Function Help(4)
  12. <?php ?> Unique Visitors Script(2)
  13. Security Issue Writing Files(1)
  14. Grabt Access To My Protected Files(2)
  15. How To Check If Fsockopen Function Is Enabled?(2)
  1. File Upload(1)
  2. No File Extension(3)
  3. Php And Flash Image Gallery(5)
  4. Arrays Outside A Function(3)
  5. File Checker-how To Check File Whith Html Through Html?(2)
  6. Php Ftp Upload Form(1)
  7. How To Display Images Of A Directory(4)
  8. Download Script For Mp3 Files(0)
  9. Updating Php File Through A Web Form(5)
  10. Endif function?(6)
  11. Need Some Help In File Browser(8)
  12. Php Configuration File(16)
  13. PHP Function To Add Previous and Next Page Feature(2)


 



- Lo-Fi Version Time is now: 8th September 2008 - 07:49 AM
<