Using URL in opendir() as absolute path

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kkhan5000
    New Member
    • Jul 2008
    • 8

    Using URL in opendir() as absolute path

    Hello,

    I would like to use an URL insttead of a local path in the following command, is it possible?

    [CODE=php]
    $url = 'http://www.mysite.com/content/';
    $dir = opendir($url);
    [/CODE]

    Thank you,

    kkhan
  • chazzy69
    New Member
    • Sep 2007
    • 196

    #2
    I don't know about that function but you can use fopen to open a file with a url, also you mabye be able to use an include statement depending on what your trying to achieve.

    Comment

    • kkhan5000
      New Member
      • Jul 2008
      • 8

      #3
      Thank you chazzy69. Here is the php code I am working. This lists and display files from a certain folder. I would like to use this code as an include for several directories, however, it always want to look for $dirpath below the current folder. I hope that a fixed url will fix this problem, but I am not sure whether opendir function can use urls instead of local paths.

      [code=php]
      <?php
      $dirpath = "content";
      $dh = opendir($dirpat h);
      while (false !== ($file = readdir($dh))) {
      $fileList[] = trim($file);

      //Don't list subdirectories
      if (!is_dir("$dirp ath/$file")){
      sort ($fileList); // sort the file list in the array
      }
      }
      reset ($fileList); // go back to the top of the array
      while (list ($key, $file) = each ($fileList))
      {
      //Truncate the file extension and capitalize the first letter
      echo "<a href='$dirpath/$file'>". htmlspecialchar s(ucfirst(preg_ replace('/\..*$/', '', $file))). "<br />";"</a>";


      }
      closedir($dh);
      ?>
      [/code]

      Comment

      Working...