SitePoint Sponsor

User Tag List

Results 1 to 12 of 12

Hybrid View

  1. #1
    SitePoint Wizard wheeler's Avatar
    Join Date
    Mar 2006
    Location
    Gold Coast, Australia
    Posts
    1,369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    open remote directory for reading

    I'm trying to open a remote directory of images and loop through them in php... but I get this:
    Code:
    Warning: opendir(http://site.com/uploads/images/0-4999/341/) [function.opendir]: failed to open dir: not implemented in /path/to/file.php on line 175
    I assumed it might be related to php.ini, and confirmed the setting:

    allow_url_fopen = On

    I also confirmed that opendir works locally.

    The source files are just plain images that are accessible in the browser.

    Any ideas on the problem?
    Studiotime - Time Management for Web Developers
    to-do's, messages, invoicing, reporting - 30 day free trial!
    Thomas Multimedia Web Development

  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why not using FTP connect? Though i have not worked like that and even used, you can try with FTP connect functions in PHP.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  3. #3
    SitePoint Wizard wheeler's Avatar
    Join Date
    Mar 2006
    Location
    Gold Coast, Australia
    Posts
    1,369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rajug View Post
    Why not using FTP connect? Though i have not worked like that and even used, you can try with FTP connect functions in PHP.
    no, because using ftp will slow the page down, and this is a file that is accessed thousands of time a day.
    Studiotime - Time Management for Web Developers
    to-do's, messages, invoicing, reporting - 30 day free trial!
    Thomas Multimedia Web Development

  4. #4
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So wheeler, are you sure that it is possible to open the remote directory with opendir() function? Or you have worked with opendir() to open remote directory before? I heard but read anywhere yet it is not possible to open remote file/directory opendir() function.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  5. #5
    SitePoint Wizard wheeler's Avatar
    Join Date
    Mar 2006
    Location
    Gold Coast, Australia
    Posts
    1,369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can't seem to get a clear answer either, i've been looking for over an hour but can't find anything much...

    some people seem to say u have to use fopen() and regex to read the remote folder contents and filter them, because opendir() doesn't work remotely - while other sources say you can open remote folders...
    Studiotime - Time Management for Web Developers
    to-do's, messages, invoicing, reporting - 30 day free trial!
    Thomas Multimedia Web Development

  6. #6
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When I give some tries i got the errors like this:
    1. $dir = "ftp://mysite.com/images/";
    Code:
    Warning: opendir(http://mysite.com/images/) [function.opendir]: failed to open dir: not implemented in C:\xampp\htdocs\test\ftp.php on line 3
    2. $dir = "http:://mysite.com/images/";
    Code:
    Warning: opendir(ftp://devraju.com/images/) [function.opendir]: failed to open dir: FTP server reports 2‘| in C:\xampp\htdocs\test\ftp.php on line 3
    And somewhere in the internet i had found this line before
    Code:
    ..... and as you seem to be aware, opendir() works on DIRECTORIES, not URLs. And opendir() only works in local directories of code running system not remove.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  7. #7
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    opendir works only with FTP resources, no http. Your options are either to parse html directory listing with regexps or to use ftp.

  8. #8
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by stereofrog View Post
    opendir works only with FTP resources, no http. Your options are either to parse html directory listing with regexps or to use ftp.
    Do you mean like this stereofrog?
    Code php:
    $dir = "ftp://ftp.mysite.com/images";
    if ($dh = opendir($dir)) {
    	while (($file = readdir($dh)) !== false) {
    		echo "filename: $file : filetype: " . filetype($dir . $file) . "\n";
    	}
    	closedir($dh);
    }

    But this gave me this error:
    Code:
    Warning: opendir(ftp://ftp.mysite.com/images) [function.opendir]: failed to open dir: FTP server reports 2| in C:\xampp\htdocs\test\ftp.php on line 3
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  9. #9
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    No opendir cannot because a remote server does not send a directory listing.

    If the server sends an HTML directory listing then you can process that.
    Or better yet use FTP, and not FTP is not slow when it comes to files on remote systems FTP was designed for it.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  10. #10
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Honestly, I've never used opendir with ftp, and I don't see any need to, since ftp_nlist works just fine.

  11. #11
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by stereofrog View Post
    Honestly, I've never used opendir with ftp, and I don't see any need to, since ftp_nlist works just fine.
    Ahh! I know with FTP functions we can do it that's why i had told wheeler to do this with FTP in my first reply post here.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  12. #12
    SitePoint Wizard wheeler's Avatar
    Join Date
    Mar 2006
    Location
    Gold Coast, Australia
    Posts
    1,369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for responses, im still skeptical that ftp is a good idea... how could opening up dozens (if not tonnes) of simultaneous ftp connections 24/7 be a speed efficient process compared to http?

    I have complete control of both servers, they are both dedicated and sitting side by side... the images are split from the main server for added speed.

    I guess it does make sense that opendir() doesn't work the same remotely as it does locally....

    hmm....

    a 3rd option would be to store all the file names in the database (half a million and counting) and simply hotlink them in. Of the three options, this is probably the best one as far as I can see. I suppose this also presents further benefits such as storing more file information, but also adds a new layer of complexity.
    Studiotime - Time Management for Web Developers
    to-do's, messages, invoicing, reporting - 30 day free trial!
    Thomas Multimedia Web Development


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
  •