Solved

Using the directoryIterator class to read remote directory

Posted on 2008-10-13
4
796 Views
Last Modified: 2009-07-29
Hi,
I am using the class to get a list of file names on my localhost like this:

foreach ( new DirectoryIterator('c:/wamp/www/name/images/etc') as $file)
{
      if (!$file->isDot())
      {
            print $file->getFilename();
      }
}

All fine.

What I want to do is to read the same directory on a remote server - to make sure when I copied the files using FTP they were all done. However, when I try placing the path in the constructor like this:

foreach ( new DirectoryIterator('/home/sites/domainname.com/public_html/images/etc') as $file)
{
      if (!$file->isDot())
      {
            print $file->getFilename();
      }
}

I get errors. Is it not possible to do this?

Any help much appreciated!

Daisy
0
Comment
Question by:daisydoos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 11

Expert Comment

by:AlexanderR
ID: 22704721
Perhaps its a security restriction on the server.  Do you HAVE to use full path?  Can your class just accept "images/etc"?
0
 

Author Comment

by:daisydoos
ID: 22705142
Hi Alexander,

Thanks for your response.

The thing is I want to compare the contents of the directory on localhost eg images/products and do the same on the remote server. If use images/products for the remote query, I am just pulling off the files on my local machine.

Any other thoughts on how I can do this?

Many thanks

Daisy
0
 
LVL 11

Accepted Solution

by:
AlexanderR earned 125 total points
ID: 22705218
Oh, sorry.
I thought both the images and the script gets uploaded.  So the script remains on your local computer but has to scan remote ftp site.  Am i correct this time?

What kind of errors do you get.  Do you use ftp specific functions , like ftp_nlist http://bs.php.net/manual/en/function.ftp-nlist.php.  You probably should post your DirectoryIterator for us to see.
0
 

Author Comment

by:daisydoos
ID: 22708906
Hi Alexander,

That's great - thanks! I am using this ftp_nlist in conjunction with the directoryIterator to compare the 2 directories - all is well - many thanks,

Daisy
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question