Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go through files in folder at another server PHP

Tags:

file

php

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.

like image 834
MmynameStackflow Avatar asked Dec 22 '25 17:12

MmynameStackflow


2 Answers

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>';
}
like image 147
MmynameStackflow Avatar answered Dec 24 '25 07:12

MmynameStackflow


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.

like image 25
Nico Cvitak Avatar answered Dec 24 '25 08:12

Nico Cvitak