SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot dcgamers's Avatar
    Join Date
    Dec 2005
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation opendir() using local directories - is it possible?

    I need someone to get me a script that can read contents of a local directory (specified) and echo out the files in that folder in php. I tried the following but It did not work.
    PHP Code:
    <?php
    $dir 
    "C:\Documents and Settings\Kaelan\Desktop\Web\GamerDay\img";

    // Open a known directory, and proceed to read its contents
       
    if ($dh opendir($dir)) {
           while ((
    $file readdir($dh)) !== false) {
               echo 
    "filename: $file : filetype: " filetype($dir $file) . "\n";
           }
           
    closedir($dh);
       }

    ?>

  2. #2
    SitePoint Member
    Join Date
    Jan 2005
    Location
    London
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Suggest escaping the slashes in $dir ie. double slashes - this always works with Windows paths for fopen()

  3. #3
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ... or replace the backslashes with forward slashes

  4. #4
    SitePoint Zealot dcgamers's Avatar
    Join Date
    Dec 2005
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @kyberfabrikken: didn't work
    @polyxena: What do you mean? Example?

  5. #5
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    When you say 'local' directory are you talking about the browsers file system?

    You cannot access the file system of the browsers computer with PHP.
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  6. #6
    SitePoint Member
    Join Date
    Jan 2005
    Location
    London
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    "C:\\Documents and Settings\\Kaelan\\Desktop\\Web\\GamerDay\\img"

    Even on Windows, eg with XAMPP, one can access the filesystem...

    eg $fp = fopen("c:\\php\\httpdocs\\index.php", "r");

  7. #7
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You can access the filesystem if the PHP code is being run on the same computer as the filesystem resides. If you are trying to access the local filesystem of a user via PHP code running on a remote server then this is not allowed (except in certain circustances - e.g. IE running an ActiveX script).
    Ian Anderson
    www.siteguru.co.uk

  8. #8
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by polyxena View Post
    "C:\\Documents and Settings\\Kaelan\\Desktop\\Web\\GamerDay\\img"

    Even on Windows, eg with XAMPP, one can access the filesystem...

    eg $fp = fopen("c:\\php\\httpdocs\\index.php", "r");


    fopen("c:\\php\\httpdocs\\index.php", "r");

    This is accessing the filesystem of the server, not of the browser, of course if your server and browser are on the same piece of hardware this is possible.
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming


Bookmarks

Posting Permissions

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