Nov 8, 2009

Getting List Of Directories And Files Using Php - PHP Function for Directory and File List

free web hosting
Open Discussion > MODERATED AREA > Computers > Programming Languages > PHP Programming

Getting List Of Directories And Files Using Php - PHP Function for Directory and File List

Corey
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

Comment/Reply (w/o sign-up)

Ao)K-General
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.

Comment/Reply (w/o sign-up)

yasir
best thing would be to Google it!

Try something like 'Advanced PHP Tutorials'

Cheers!
Yasir smile.gif

Comment/Reply (w/o sign-up)

HmmZ
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 )

Comment/Reply (w/o sign-up)

bjrn
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().

Comment/Reply (w/o sign-up)

mobious
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);

 

 

 


Comment/Reply (w/o sign-up)

FeedBacker
Good Php Directory
Getting List Of Directories And Files Using Php

Here is a good PR4 Php directory

Www.Businessservicesuk.Com

-reply by Pete

Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : Directories Files Php Php Function Directory File

  1. How To Display Images Of A Directory - (5)
    I am trying to do a simple thing. I want to display all the images of a directory on a single page
    with the checkbox next to each image, so that i can select multi images and i can delete selected
    images. Following few lines of code display the images of a directory.. i need help to put the
    check boxes with each image. and I dont understand how can i select multi images with check box and
    then delete them. I hope someone can help. thanks. CODE $path = "./"; $dir_handle =
    @opendir($path) or die("Unable to open folder"); while (false !== ($file = readdir($dir_han...
  2. Securing Upload Directory - proper way to do it? (6)
  3. Pages In 1 File - ?? (10)
    I know its possible to put many pages inside 1 file. But how? Lets say you have a guestbook with
    different pages for signing and viewing. How to make so those pages are in 1 file? /huh.gif"
    style="vertical-align:middle" emoid=":huh:" border="0" alt="huh.gif" />...
  4. Error When Using file_put_contents() - failed to call to undefined function (5)
    Hey all, I decided to write a script which writes some text to a file, but I have a problem when I
    execute the script, I get a fatal error: QUOTE(homepage) Fatal error : Call to undefined
    function: file_put_contents() in /home/cmatcme/public_html/afile.php on line 55 This is the
    code I'm using to write the file: $ipfnsdoc = "/home/cmatcme/public_html/afolder/afile.txt";
    if (!is_readable($ipfnsdoc)) { echo "File cannot be read"; $stopload = 1; } if
    (!is_writable($ipfnsdoc)) { echo " \nFile cannot be written to"; $stoploa...
  5. How To Use A Link To Call Function In Php? - (9)
    The title says it all, really. How do you call a function using in PHP? I'm doing a project
    and I stumbled upon this problem. I don't want to use query string in the href part like
    since that would mess up the other part of my code. Can anyone pleae help me? I've pasted the
    code below. /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /> Thanksh.
    CODE   function display($x){ //coding goes here.   } ?> Display itmes ...
  6. How To Check If Fsockopen Function Is Enabled? - (3)
    Hi, I have VPS (virtual private server) and I have access to php.ini file. Is there any script that
    will show that fsockopen function is enabled or where do I have to enable it? Searched google and
    here and couldn't find anything. Thanks! ...
  7. Php Configuration File - "config.php" (18)
    I did create this topic mainly because I want to know everything about that configuration file. I
    will post other replies if I want to know more depending on your experience. Is this code correct
    for that file: CODE $host="localhost"; $dbname="XXX"; $dbuser="XXX"; $dbpass="XXX";
    $connection=mysql_connect($host, $dbuser, $dbpass) or die(mysql_error()); mysql_select_db($dbname)
    or die(mysql_error()); ?> Add your suggestions or improve it....
  8. How To Sort Files Of A Directory using Php - (12)
    The following code displays the files of folder...but they are displaced by the order of adding... i
    want to sord the files / folders alphabetically and sord by accending order and by decending
    order.. can some one help me. $path = ""; $dir_handle = @opendir($path) or die("Unable to open
    $path"); echo "Directory Listing of $path "; while($file = readdir($dir_handle)) {
    if(is_dir($file)) { continue; } else if($file != '.' && $file !=
    '..') { echo " $file "; } } //closing the directory
    closedir($dir...
  9. File Uploading Issues - (5)
    i have never tried to have files uploaded and i am still not able to do so. here is the codes that i
    am using right out of the php manual and it still isnt working. i have also listed the
    warnings/errors listed on the resulting page. my permissions are set to 777 also. i have a folder
    set up on my server as "uploads". i am however not sure if i have a default temp folder on my
    server. can anyone help me figure out what i am not doing correctly or what my next step is? this
    is the form that i am using: html Code: CODE        Choose a file to upload:     ...
  10. Php - Fetching Random Line From A Text File - and displaying it using AJAX/iframe (0)
    What you should know: HTML, PHP basics (executing php scripts) Examples: Using AJAX Using
    iframe Download Examples Using this script you can display a random quote/fact every time a
    visitor clicks the link. It happens dynamically without reloading the whole page. Useful for keeping
    a site fresh and lively. For example, you can have it in "About Me" page of a website which is
    rarely updated. All the quotes are stored in a text file separated by a line break. Although I have
    included a sample collection, you are free to modify or create your own. Thanks to Davi...
  11. Search Engine/ Function - (0)
    Hi there, can anyone please give me a tutorial or something on how to create a search engine sort of
    thorugh PHP. I don't have any background knowledge of PHP but im trying to learn it so please
    could someone help! Btw, im talkinng about a search engine which you type in a url website and wen
    you click on go it will go straight o that website THROUGH another search engine. For example, my
    friend, not saying me, has a sort of search engine where he just types in the url of the website and
    when he clicks search it automatically goes the website homepage THROUGH phpr...
  12. Script: Php Jukebox - A one file script! (6)
    This scripts is so simple, you dont need to edit ANY of it! All you have to do is make a folder
    called 'songs' and put some audio files in it. Here is the whole page, I named it index.php
    and put it in a folder called 'music': CODE PHP jukebox ©2005 Craig lloyd.
    All rights reserved. Visit cragllo.com for more scripts --> /** * ©2005 Craig lloyd. All rights
    reserved. * * Mod Title:           Simple PHP Jukebox * Author:              Craig Lloyd * Author
    Email:        cragllo@cragllo.com * Author Homepage:     http://www.cragllo.com/ * Des...
  13. PHP Function To Add Previous and Next Page Feature - useful php function (5)
    CODE function navigationbar($start_number = 0, $items_per_page = 50, $count) {    // Creates a
    navigation bar    $current_page = $_SERVER ;     if (($start_number         $start_number = 0;
        }     $navbar = "";     $prev_navbar = "";     $next_navbar = "";     if ($count >
    $items_per_page) {         $nav_count = 0;         $page_count  = 1;         $nav_passed = false;
            while ($nav_count             // Are we at the current page position?             if
    (($start_number                 $navbar .= " ";                 $nav_passed = true;       ...
  14. Linux/ Apache /mod_rewrite Issue - Error when accessing a file (4)
    running on Ubuntu 8.04 with an XAMPP - php5.2.5, Apache 2., etc Getting this error when I try to
    access an sNews CMS which requires mod_rewrite and is installed locally: QUOTE Apache/2.2.8
    (Unix) DAV/2 mod_ssl/2.2.8 OpenSSL/0.9.8e PHP/5.2.5 mod_apreq2-20051231/2.6.0 mod_perl/2.0.2
    Perl/v5.10.0 configured -- resuming normal operations /opt/lampp/htdocs/jim/snews/.htaccess:
    RewriteBase: argument is not a valid URL /opt/lampp/htdocs/jim/snews/.htaccess: RewriteBase:
    argument is not a valid URL Using this link: http://localhost/jim/snews/snews16_ema...
  15. Php Ftp Upload Form - Adding User Directory to PHP Upload Form - Help (1)
    Alright I am trying to have a PHP FTP Upload Form that allows the user to create the directory
    folder for where they want to upload there files to. example: Main Directory: vainsoft.com There
    directory: vainsoft.com/modeling or vainsoft.com/photography But I dont want them to be able to
    upload things into the main directory, only sub-directories, is that possible with this coding that
    I have: //uses $_FILES global array //see manual for older PHP version info //This function
    will be used to get the extension from the filename function get_extension($file,$length...
  16. Include File.php?id=something - using the include() function (13)
    Well, I am making a full CMS system for my site, and want to make the index.php file to include the
    view.php?id=1 file. I tried with this code, but it didn't work: CODE This is the error
    I get: CODE Warning: main(view.php?id=1) : failed to open stream: Invalid argument in
    C:\server\xampp\htdocs\test\index.php on line 1 Warning: main() : Failed opening
    'view.php?id=1' for inclusion (include_path='.;C:\server\xampp\php\pear\') in
    C:\server\xampp\htdocs\test\index.php on line 1 So what can I do?...
  17. How Good Is This Data Cleaning Function? - (2)
    Hi all, this is my first function and as part of a script and i just want to know a couple of
    things. here is the code for the function: CODE function clean($dirty_string) {
    $muddy_string = stripslashes($dirty_string); $murky_string = strip_tags($muddy_string);
    $clean_string = htmlentities($murky_string);      }; ?> So the first thing is how secure is it?
    the script this will be used in connects to a database and sends an email so it needs to stop SQL
    injections and any email abuse it might cause, also the data stored in the database will be usaed as
    par...
  18. Need Some Help In File Browser - listing all sub folders and files in them. (8)
    Hey I want to create a very simple file browser, so that, it reads all the sub-folders which are
    places in a directory, and the files inside the sub-folders (It reads only files inside sub-folders
    and list them in simply. ) Also, it creates a directory (any name) inside each sub folder. My
    Following code reads on the files inside the main directory, it does not read the files inside the
    sub-folders.. I appreciate any help. CODE $path = "./"; $dir_handle = @opendir($path) or
    die("Unable to open $path"); while ($file = readdir($dir_handle)) { if($file == "." || $fil...
  19. Endif function? - (6)
    As you get noticed before, I am studying PHP in examples like using the tutorials as well as books
    itself. Through my readings, I get this function CODE a lot of times. So, what do you mean
    by this function, and what does it do exactly?...
  20. Updating Php File Through A Web Form - (5)
    Hello, i'm not sure if this can be done with php or not but what i need is a way to make an php
    file that have an html form on it and it will take the info you put in to that form and write it to
    an existing php file, for example: if i have the file news.php and the file news_update.php. if you
    went to news_update.php you would get an form with a text area for you to write a new addition for
    the news.php file and when you hit submit it will add what you typed in the form to the file
    news.php. If this is going to be a big code or a hard one to make but some one think...
  21. Download Script For Mp3 Files - (0)
    Hello, I'm looking for a download script for sound files (e.g. mp3, avi, wma, and other ones).
    i have found a few download scripts but they would not work for sound files for some reason. also
    this will not be used for allowing downloading of illegal or riped music, what i will be using this
    script for is i'm making a site for my church and the pastor wants to be able to recored the
    services and then have me upload them to the site so that the church members can download them for
    what ever reason. If some one could tell me how to make one or could show me a plac...
  22. Change Permission With Php Code - code to change files' and folders' permissions? (3)
    As everyone know, there two ways (that I can think of) to change files' and directories'
    permissions. One is to change it in your cPanel's Disk Manager and the other is with an FTP
    client that supports chmod. Well, I'm doing something for my site that requires files to have
    full permissions (Execute, Write, and Read on all three groups). At first, I thought that if I made
    the directory 777, then every file created in that directory will be 777 as well. I'm wrong. An
    alternative to doing this is to change each file permission myself, but that would be...
  23. File Checker-how To Check File Whith Html Through Html? - (2)
    edit:sorry for the mistake it is php not html and its with not whith my code checking script= CODE
    $file = '$CHECK'; if (file_exists($file)) {     echo "The file $filename exists"; } else
    {     echo "The file $filename does not exist"; } ?> my question is how to check the file whith
    html example:on a page a text box is provided and a button the user writes a file name (or website)
    the user clicks on the submit button then it checks and show it (with the code above) i got the
    code CODE $filename=$_POST ; if (file_exists($filename)) {     echo "The...
  24. Php And Flash Image Gallery - Need some help in creating or editing an xml file while viewing some o (5)
    Hello there and thanks for the helping hand you are offering. PHP newbie here! /ph34r.gif"
    style="vertical-align:middle" emoid=":ph34r:" border="0" alt="ph34r.gif" /> So here is my problem:
    On my website I have a flash image gallery.The way the gallery works is by uploading pictures in a
    folder and editing? an xml file.(pics.xml) where it adds the following code when you upload a
    picture: CODE           etc... Now I have users that upload products they sell on the
    website or they advertise their business(hotels, jewellers, car resellers,...) So for eve...
  25. Mail() Clone - A PHP mail() function clone (5)
    A lot of free web hosts have disabled the mail() function so you cannot send emails using PHP. Does
    anybody know of a script that makes a function "like" mail but is able to be installed in a web
    accessible directory and called included into another script and called like that? Or maybe you know
    how to make such a function? I just really need to find a way around the free hosts turning of the
    mail() function. I need to figure out a way to send emails....
  26. Arrays Outside A Function - Need to have arrays available to all functions. (3)
    I've got a bunch of arrays that i want to use for more then 1 function. when i declear the
    arrays outside a function i cant use it in a function. This code was originally written in
    javascript by another person but since I plan to use it and extend it with php I had to change it
    from javascript to php code. In the javascript code the arrays were decleared outside the functions
    with 'var arrayname' I read somewhere that declearing javascript variables with
    'var' gives it global access. Any ideas on how I can go about declearing 1 set of these
    arrays t...
  27. The Best Zip Function - (1)
    hi my 6th code is very useful, you can zip your file by this: CODE class dZip{     var
    $filename;     var $overwrite;          var $zipSignature = "\x50\x4b\x03\x04"; // local file header
    signature     var $dirSignature = "\x50\x4b\x01\x02"; // central dir header signature     var
    $dirSignatureE= "\x50\x4b\x05\x06"; // end of central dir signature     var $files_count  = 0;
        var $fh;          Function dZip($filename, $overwrite=true){         $this->filename  =
    $filename;         $this->overwrite = $overwrite;     }     Function addDir($dirname,
    $fileComments=&#...
  28. No File Extension - (3)
    On MediaWiki, the URL of the content is http://YOURWIKI.com/index.php/Blah Is it possible to
    create a page or two that doesn't have a file extension? If so, how is it done?...
  29. Grabt Access To My Protected Files - grabt access to my protected files (2)
    Hi all, I am sure all of you are great programers but First i am no code programmer i am just
    trying to learn to run my sites, will the problem is i got a code from the web to protect my files
    ,1st i want to know how to work it out then i will try other things but can't let it go without
    a fight thanx all php: CODE if ( ! defined( 'myname' ) ) {         print "You
    cannot access this file directly.";         exit(); } customer data here ?> now i
    can't access my files what is the method to access them all i want is to protect the f...
  30. File Upload - File upload (1)
    I need to add a facility on my customer's website so his clients can send him jobs, typically
    5mb - 50mb. I've looked around the web and researched this, and tried a few tests (failed), but
    my brain's beginning to hurt. Could someone please tell me the best way to go about this,
    please. The site is done in Flash, but I'm sure a link to an html page would be ok if necessary....



Looking for list, directories, files, php, php, function, directory, file, list

Searching Video's for list, directories, files, php, php, function, directory, file, list
See Also,
advertisement


Getting List Of Directories And Files Using Php - PHP Function for Directory and File List

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com