By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,339 Members | 1,700 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,339 IT Pros & Developers. It's quick & easy.

Get a list of files on a website

P: n/a
Greetings,

I need to get a list of all files in a particular virtual directory on
a web site, such as -
http://www.myServer.com/FileStore

I tried using the directory functions, but this doesn't work.

if($dirHandle = opendir("http://www.myServer.com/FileStore/"))
{
while(false !== ($file = readdir($dirHandle)))
{
print($file."<br>");
}
}
closedir($handle);
}

Is there a way to do this?

Thanks,
Harold

Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Harold Crump" <or**********@yahoo.com> wrote in
news:11**********************@f14g2000cwb.googlegr oups.com:
Greetings,

I need to get a list of all files in a particular virtual directory on
a web site, such as -
http://www.myServer.com/FileStore

I tried using the directory functions, but this doesn't work.

if($dirHandle = opendir("http://www.myServer.com/FileStore/"))
{
while(false !== ($file = readdir($dirHandle)))
{
print($file."<br>");
}
}
closedir($handle);
}

Is there a way to do this?


opendir is meant to be used on the same server on which the script is
running.

you can't just connect to any website folder on the internet and download
everything in it!!
Jul 17 '05 #2

P: n/a
NC
Harold Crump wrote:

I need to get a list of all files in a particular virtual
directory on a web site, such as -
http://www.myServer.com/FileStore

I tried using the directory functions, but this doesn't work.
Directory functions only work on local file systems, not
over HTTP. This is clearly spelled out in the PHP Manual.
Is there a way to do this?


Yes, but only under two conditions (both are required):

1. There is no directory index in the target directory, and
2. The HTTP server on the remote system is allowed to
provide the directory listing in response to a request
for the directory name.

In Apache, the name of the directory index is set by the
DirectoryIndex directive. To allow listing the contents
of the directory, you should specify the Options Indexes
directive.

Cheers,
NC

Jul 17 '05 #3

P: n/a
NC wrote :
Harold Crump wrote:

I need to get a list of all files in a particular virtual
directory on a web site, such as -
http://www.myServer.com/FileStore

I tried using the directory functions, but this doesn't work.


Directory functions only work on local file systems, not
over HTTP. This is clearly spelled out in the PHP Manual.
Is there a way to do this?


Yes, but only under two conditions (both are required):

1. There is no directory index in the target directory, and
2. The HTTP server on the remote system is allowed to
provide the directory listing in response to a request
for the directory name.

In Apache, the name of the directory index is set by the
DirectoryIndex directive. To allow listing the contents
of the directory, you should specify the Options Indexes
directive.

Cheers,
NC


Even with these two conditions met, how would the php script know what
the files are? Wouldnt the return result just be an HTML page with <a>
tags that may or may not be links to files?

The web server software "apache", "IIS", etc would each spit out the
directory listing differently. However, all in HTML.

I would have thought the only way to do this would be to an FTP server.

--
if the oil light is on, dont think it will just go away

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.