...

View Full Version : List files without OPENDIR ?



Arnaud
01-14-2008, 12:59 PM
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 !

shyam
01-14-2008, 01:12 PM
try scandir or glob

Arnaud
01-14-2008, 01:55 PM
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! :thumbsup:

Arnaud
01-17-2008, 03:31 PM
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:


<?
$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!

Arnaud
01-17-2008, 03:51 PM
Well... I found this little script that does the job as expected:



$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_load, 8192);
}

fclose($fp_load);
return $content;
}
}


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

Fou-Lu
01-17-2008, 03:52 PM
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.

kbluhm
01-17-2008, 03:59 PM
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.

Arnaud
01-17-2008, 04:09 PM
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:



$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!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum