How i can remove "./" from first of the name in output data!!

Discussion in 'PHP' started by raminr63, Jun 3, 2012.

  1. #1
    Hi

    in my php out put i get this data:

    ./dir.php 9e72b711c24294c992824fbe9014f815 124 ./echo.php 51324b9fc549f4b06148e4ff7674518e 239 ./New Text Document.txt d41d8cd98f00b204e9800998ecf8427e 0 ./update.php 90d1bd336fd6604a9bff164099349766 910

    i want to remove "./" form the first of file names in output data.

    what can i do?!

    my php code:


    <?PHP
    require_once "./dir.php";
    require_once "./echo.php";
    
    
      function getFileList($dir)
      {
        // array to hold return value
        $retval = array();
    
    
        // add trailing slash if missing
      //  if(substr($dir, -1) != "/") $dir .= "/";
    
    
        // open pointer to directory and read list of files
        $d = @dir($dir) or die("getFileList: Failed opening directory $dir for reading");
        while(false !== ($entry = $d->read())) {
          // skip hidden files
          if($entry[0] == ".") continue;
          if(is_dir("$dir$entry")) {
            $retval[] = array(
              "name" => "$dir$entry/",
              "size" => 0,
               "Stream" => md5_file("$dir$entry")
            );
          } elseif(is_readable("$dir$entry")) {
           $retval[] = array(
              "name" => "$dir$entry",
              "size" => filesize("$dir$entry"),
             "Stream" => md5_file("$dir$entry")
            );
          }
       }
        $d->close();
    
    
        return $retval;
      }
    ?>
    
    Code (markup):


    update.php:



    and echo.php:

    
    <?PHP
      // output file list as HTML table
      foreach($dirlist as $file) {
        echo "<tr>\n";
        echo "<td>{$file['name']}</td>\n";
        echo "<td>{$file['Stream']}</td>\n";
        echo "<td>{$file['size']}</td>\n";
      }
      echo "\n";
    ?>
    
    Code (markup):
    and dir.php:

    
    <?PHP
      // examples for scanning the current directory
      $dirlist = getFileList(".");
      $dirlist = getFileList("./");
    ?>
    
    Code (markup):
    Thank you
     
    raminr63, Jun 3, 2012 IP
  2. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #2
    You couldn't of written this code then lol
     
    NetStar, Jun 3, 2012 IP
  3. kbduvall

    kbduvall Peon

    Messages:
    71
    Likes Received:
    3
    Best Answers:
    4
    Trophy Points:
    0
    #3
    
    <?PHP
      // output file list as HTML table
      foreach($dirlist as $file) {
        echo "<tr>\n";
        echo "<td>". ltrim($file['name'], './') ."</td>\n";
        echo "<td>{$file['Stream']}</td>\n";
        echo "<td>{$file['size']}</td>\n";
      }
      echo "\n";
    ?>
    
    PHP:
     
    kbduvall, Jun 3, 2012 IP
  4. y8games2012

    y8games2012 Peon

    Messages:
    17
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    i can't write code in this comment panel
     
    y8games2012, Jun 3, 2012 IP
  5. manhtv157

    manhtv157 Peon

    Messages:
    24
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    3
    #5
    You can use this script
     
    manhtv157, Jun 3, 2012 IP