www.webdeveloper.com
Results 1 to 11 of 11

Thread: opendir

  1. #1
    Join Date
    Dec 2009
    Posts
    86

    opendir

    hi,
    i want a function opendir folder and get all php files name and size... if hi have more folder in this folder then hi open thease folders and get php files name and get size ......
    thanx in advance
    Last edited by aadi; 04-08-2010 at 03:56 AM.

  2. #2
    Join Date
    Dec 2009
    Posts
    86
    i have done this
    (one have one problem get file size)
    PHP Code:
    function ListFolder($path)
    {

        
    //using the opendir function
        
    $dir_handle = @opendir($path) or die("Unable to open $path");
       
        
    //Leave only the lastest folder name
        
    $dirname end(explode("/"$path));
       
        
    //display the target folder.
       
    $dirname;
       
        while (
    false !== ($file readdir($dir_handle)))
        {
            if(
    $file!="." && $file!="..")
            {
                if (
    is_dir($path."/".$file))
                {
                    
    //Display a list of sub folders.
                    
    ListFolder($path."/".$file);
                }
                else
                {           
                
    $fileext substr(strrchr($file"."), 1);
                if(
    $fileext=="php" )//if files are php
                
    {
                    
    //Display a list of files.
                   
    echo $file;
                    echo 
    "<br>";
                }
                }
            }
        }
        
       
        
    //closing the directory
        
    closedir($dir_handle);

    HTML Code:
    <div class="dmxtree" id="FolderView">
    <?php ListFolder("files/"); ?>
    </div>

  3. #3
    Join Date
    Mar 2010
    Posts
    2,803
    you can get the size of the file by using

    Code:
     
    $size = filesize(relative_path_to_file);

  4. #4
    Join Date
    Dec 2009
    Posts
    86
    i alredy try this butt hi is showing this Warning
    Warning: filesize() [function.filesize]: stat failed for

  5. #5
    Join Date
    Mar 2010
    Posts
    2,803
    are you sure you have the correct relative path to your file from the directory where your script is running.?

  6. #6
    Join Date
    Dec 2009
    Posts
    86
    yes input is this
    PHP Code:
    <?php
    function ListFolder($path)
    {

        
    //using the opendir function
        
    $dir_handle = @opendir($path) or die("Unable to open $path");
       
        
    //Leave only the lastest folder name
        
    $dirname end(explode("/"$path));
       
        
    //display the target folder.
       
    $dirname;
       
        while (
    false !== ($file readdir($dir_handle)))
        {
            if(
    $file!="." && $file!=".." && $file!="Thumbs.db" )
            {
            
                if (
    is_dir($path."/".$file))
                {
                    
    //Display a list of sub folders.
                    
    ListFolder($path."/".$file);
                }
                else
                {            
                
    $fileext substr(strrchr($file"."), 1);
                if(
    $fileext=="php" )//if files are php
                
    {
                    
    //Display a list of files.
                   
    echo "<b>File name is</b> ".$file;
                    echo 
    "<br>";
                    echo 
    "<b>File size is</b> ".filesize($file);// line 32
                    
    echo "<br>";
                }
                }
            }
        }
        
       
        
    //closing the directory
        
    closedir($dir_handle);
    }
    ?>
    and output is
    http://i42.tinypic.com/a05ci.gif

  7. #7
    Join Date
    Mar 2010
    Posts
    2,803
    Try some basic debugging:

    Just above

    PHP Code:
    echo "<b>File size is</b> ".filesize($file);// line 32 
    insert

    PHP Code:
    echo 'File path =  '.$file.'<br />'
    and make sure the relative file path from the directory where you are running the script is correct. Also, maybe the file size is too large - maybe there is a 2GB limit.

  8. #8
    Join Date
    Dec 2009
    Posts
    86
    ok i try this

  9. #9
    Join Date
    Dec 2009
    Posts
    86
    you mean this
    PHP Code:
    echo  $path."".$file."<br />"// line 32 

  10. #10
    Join Date
    Dec 2009
    Posts
    86
    if i insert
    PHP Code:
    echo 'File path =  '.$file.'<br />'
    THEN OUTPUT IS
    File name is edit_profile.php
    File path = edit_profile.php
    File name is forget_password.php
    File path = forget_password.php
    File name is includ.php
    File path = includ.php
    File name is check.php
    File path = check.php
    File name is notfound.php
    File path = notfound.php
    File name is pagination_interface.php
    File path = pagination_interface.php
    File name is notfound.php
    File path = notfound.php
    File name is pagination_interface.php
    File path = pagination_interface.php
    File name is notfound.php
    File path = notfound.php
    File name is pagination_interface.php
    File path = pagination_interface.php
    File name is getrss.php
    File path = getrss.php
    File name is index.php
    File path = index.php

    I alredy have file path i want just file size...............

  11. #11
    Join Date
    Mar 2010
    Posts
    2,803
    that means all those files will have to be in the same folder as the script you are running is in for filesize() to work.

    If they are not then maybe try

    Code:
     
    $size = filesize($path.$file);

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles