-2

i have a url like this: http://mahboobifar.com/refah/3 when you open url, you can see the list of files on that folder. and i want to get that list from remote server. i have already seen this link: Get list of files from HTTP directory with PHP but its not help me. now how can i get this list using php? also i have to mention that fopen() and file_get_contents() are blocked in my target host.

Community
  • 1
  • 1
  • possible duplicate of [Get list of files from HTTP directory with PHP](http://stackoverflow.com/questions/22965420/get-list-of-files-from-http-directory-with-php) **See below!** – Szabolcs Páll Aug 26 '15 at 10:07

1 Answers1

0
<?php

if ($handle = opendir('/path/to/files')) {
    echo "Directory handle: $handle\n";
    echo "Entries:\n";

    /* This is the correct way to loop over the directory. */
    while (false !== ($entry = readdir($handle))) {
        echo "$entry\n";
    }

    closedir($handle);
}
?>

The code above is from http://php.net/manual/en/function.readdir.php. This will list all entries in the directory, you obviously have to extend it a bit to have something similar to the server index. There are other codes and function references there as well.

Szabolcs Páll
  • 1,402
  • 6
  • 25
  • 31
  • your code just working for local server. but i want to get directory from other sever. and that code doesn't work. – Armin Mahboobifar Aug 26 '15 at 09:16
  • It works on any server running the correct version of php. If you try to get this list from a (remote) server you don't have (write) access to, please rephrase your question. Also worth noting that the availability of the file/folder index is depending on the server settings and is generally unavailable/hidden by server settings and/or routing for security reasons. – Szabolcs Páll Aug 26 '15 at 09:27
  • yes, it's true about security reasons and etc. but i can see that directory in my browser, and i just want to get that with php... – Armin Mahboobifar Aug 26 '15 at 10:01
  • Ah ok, then you will pretty much need what's in the Q/A you posted, you just need to use cUrl instead of file_get_contents. Take a look at the cUrl doc and combine it with the answer from there, don't post a new question just to have a ready-made code that fits your specific needs. – Szabolcs Páll Aug 26 '15 at 10:06
  • please help me about this... :( i'm looking for it few days and i'm failed :( would you please give me a code that doing my purpose? – Armin Mahboobifar Aug 26 '15 at 10:19
  • http://davidwalsh.name/curl-download you can use this function in the place of file_get_contents in the other question. – Szabolcs Páll Aug 26 '15 at 10:22