3

I've got two servers. One for the files and one for the website.

I figured out how to upload the files to that server but now I need to show the thumbnails on the website.

Is there a way to go through the folder /files on the file server and display a list of those files on the website using PHP?

I searched for a while now but can't find the answer. I tried using scanddir([URL]) but that didn't work.

MmynameStackflow
  • 1,251
  • 3
  • 19
  • 39

3 Answers3

3

I'm embarrassed to say this but I found my answer at another post:

PHP directory list from remote server

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;

    }
}


$matches = array();

preg_match_all("/(a href\=\")([^\?\"]*)(\")/i", get_text('http://www.xxxxx.com/my/cool/remote/dir'), $matches);

foreach($matches[2] as $match) {
    echo $match . '<br>';
}
Community
  • 1
  • 1
MmynameStackflow
  • 1,251
  • 3
  • 19
  • 39
1

scandir will not work any other server but your own. If you want to be able to do such a thing your best bet to have them still on separate servers would be to have a php file on the website, and a php file on the file server. The php file on your website could get file data of the other server via the file server php file printing data to the screen, and the webserver one reading in that data. Example:

Webserver:

<?php
$filedata = file_get_contents("url to file handler php");
?>

Fileserver:

<?php
echo "info you want webserver to read";
?>

This can also be customized for your doing with post and get requests.

Nico Cvitak
  • 471
  • 4
  • 7
1

I used the following method:

I created a script which goes through all the files at the file server.

$fileList = glob($dir."*.*");

This is only possible if the script is actually on the fileserver. It would be rather strange to go through files at another server without having access to it.

There is a way to do this without having access (read my other answer) but this is very slow and not coming in handy.

I know I said that I didn't have access, but I had. I just wanted to know all the possibilities.

MmynameStackflow
  • 1,251
  • 3
  • 19
  • 39