Search code examples
phprackspaceopendirakamai

Can I use PHP opendir() on a external URL?


Possible Duplicate:
PHP - opendir on another server

Something like this:

opendir(http://super.cdn.com/running_order_image/sale/587/)

The opendir is being used to check the contents of a Rackspace Cloud Files Akamai bucket.

I am looping through a structure like this

587/
587/587_rubyred
587/587_rubyred/front.jpg
587/587_rubyred/back.jpg

I am trying to return the 587_rubyred part. Basically my MySQL query loops through the 587 and 834 and other numbers, I then check the directory for those numbers and return the first subfolder.


Solution

  • If you want to connect to rackspace cloud files, I'd suggest using the API located at https://github.com/rackspace/php-cloudfiles

    $auth = new CF_Authentication('<RACKSPACELOGIN>','<RACKSPACEKEY>');
    $auth->authenticate();
    $conn = new CF_Connection($auth);
    $cloudFolder = $conn->get_container('<RACKSPACECONTAINER>');    
    $cloudImages = $cloudFolder->get_objects();
    
    foreach($cloudImages as $image)
    {
      echo '<li>' . $image->name . '</li>';
    }
    

    edit: you will then be able to perform the following

    $cloudImages = $cloudFolder->get_objects(0,NULL,NULL,'587/587_rubyred');