Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jan 2008
    Location
    Geneva, Switzerland
    Posts
    413
    Thanks
    12
    Thanked 29 Times in 29 Posts

    List files without OPENDIR ?

    Hi folks,

    Is there any way to list the files in a directory without using the OPENDIR function?

    I cannot use OPENDIR because the server is running in safe mode:

    Warning: opendir() [function.opendir]: SAFE MODE Restriction in effect. The script whose uid is 594 is not allowed to access /home/.sites/120/site35/web owned by uid 99

    Thanks for your help !

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    try scandir or glob
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #3
    Regular Coder
    Join Date
    Jan 2008
    Location
    Geneva, Switzerland
    Posts
    413
    Thanks
    12
    Thanked 29 Times in 29 Posts
    Hi!
    Thanks for your answer.

    The scandir function gives me the same error (SAFE MODE).
    But the glob should be fine for what I need.

    Thanks again, topic closed!

  • #4
    Regular Coder
    Join Date
    Jan 2008
    Location
    Geneva, Switzerland
    Posts
    413
    Thanks
    12
    Thanked 29 Times in 29 Posts
    I am re-using my old post because my new question is still related to the same issue.

    Can the glob() function be used to list files from a remote location?

    I would like to list *.csv files from another website: http://www.remotesite.com/folder/*.*

    This remote website is not on the same server !

    I tried the following without success:
    PHP Code:
    <?
    $path 
    "http://www.remotesite.com/folder/";
    $files "*.csv";

    foreach (
    glob($path.$files) as $filename) {
        echo 
    $filename."\n";
    }
    ?>
    Any idea?
    Is there another function I could use to achieve what I want?
    Thanks in advance!

  • #5
    Regular Coder
    Join Date
    Jan 2008
    Location
    Geneva, Switzerland
    Posts
    413
    Thanks
    12
    Thanked 29 Times in 29 Posts
    Well... I found this little script that does the job as expected:

    PHP Code:
    $matches = array();

    preg_match_all("/(a href\=\")([^\?\"]*)(\")/i"get_text('http://www.remotesite.com/folder/'), $matches);

    foreach(
    $matches[2] as $match)
    {
        echo 
    $match '<br>';
    }

    function 
    get_text($filename)
    {
        
    $fp_load fopen("$filename""rb");
        
        if ( 
    $fp_load )
        {
            while ( !
    feof($fp_load) )
            {
                
    $content .= fgets($fp_load8192);
            }
        
            
    fclose($fp_load);
            return 
    $content;
        }

    Is that the best way to do it? If anybody has a better way, please let me know!
    Thanks.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Note: This function will not work on remote files as the file to be examined must be accessible via the servers filesystem.
    Directly from the PHP website.
    For remote access, try something like the ftp extensions.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #7
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Yeah, if someone has a blank index file to block viewing of an open directory, that code is useless. All is it doing is grabbing the contents and parsing all links to get file names.

  • #8
    Regular Coder
    Join Date
    Jan 2008
    Location
    Geneva, Switzerland
    Posts
    413
    Thanks
    12
    Thanked 29 Times in 29 Posts
    Well this is actually what I need. There is no index file to block displaying the content (it's my partner website and I need to list his files, so he did it that way).

    Now I will use something like this to 'copy' the file from his server to my server:

    PHP Code:
    $content file_get_contents('http://www.remotesite.com/folder/thefile.csv');
    $dir "myserver/csv/";
    $fp fopen($dir.'thefile.csv''w');
    fwrite($fp$content);
    fclose($fp); 
    So I managed to do what I need... List files from my partner's server - one click copy of the file I want to my server.

    I just wanted to know if there was a better way to achieve this but since it's working fine, that should be ok for me.

    Thanks guys!
    Last edited by Arnaud; 01-17-2008 at 04:10 PM. Reason: Late spell check...


  •  

    Posting Permissions

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