• 0

[PHP] Pulling from multiple sources


Question

BinaryData

Hey Programmers!

 

I've asked two others for help on this, but they are incredibly busy, and it's a good learning opportunity for me. So, here's what needs to be done..

 

I need to be able to pull the file directory from multiple FTP/HTTP directories and have it output onto one index page. 

 

An Example...

 

Server 1 FTP - > Main Display
Server 2 FTP - > Main Display

Server 3 FTP - > Main Display

 

Main Display would have all the Files/Folders Listed.

 

I've tried Googling, but I keep getting things for just pulling from a single directory, which doesn't help me.

Link to post
Share on other sites

9 answers to this question

Recommended Posts

  • 0
+Dick Montage

So you're going to need to pull from 3 and simply merge the output I'm afraid.

Link to post
Share on other sites
  • 0
BinaryData
Just now, Nik L said:

So you're going to need to pull from 3 and simply merge the output I'm afraid.

Pretty much, I was told to just have each "server" output, and then have the main read those and display that. But that seems a bit more complicated, and as Seahorsepip told me "Please don't touch PHP..." :p

Link to post
Share on other sites
  • 0
+Dick Montage

Then don't do it in PHP - your call.  Personally I argue it's absolutely fine for smaller scale stuff.  So you want to connect to 3 file locations (let's currently forget whether thats a folder or FTP) and display all 3 as an amalgamated list?  I can't fathom why that's useful, but that's your call and I assume you have a reason.

 

I'd create an object to represent each file, including it's location.  For each location, create objects per file, and store these within an array or something.  Then sort your array, then have a function to parse the contents to your desired output.  That way you have one list representing really 3.

Link to post
Share on other sites
  • 0
BinaryData
6 minutes ago, Nik L said:

Then don't do it in PHP - your call.  Personally I argue it's absolutely fine for smaller scale stuff.  So you want to connect to 3 file locations (let's currently forget whether thats a folder or FTP) and display all 3 as an amalgamated list?  I can't fathom why that's useful, but that's your call and I assume you have a reason.

 

I'd create an object to represent each file, including it's location.  For each location, create objects per file, and store these within an array or something.  Then sort your array, then have a function to parse the contents to your desired output.  That way you have one list representing really 3.

I'll look into this as soon as my Linux+ Pre-Assessment test is finished.

Link to post
Share on other sites
  • 0
Jack W

By 'display', I am assuming you mean that when you visit either the IP or the domain of the server that it is attached too, it shows the folder and file hierarchy for what it contains? And you want to merge all of them to be displayed into one page?

Link to post
Share on other sites
  • 0
BinaryData
1 minute ago, Jack W said:

By 'display', I am assuming you mean that when you visit either the IP or the domain of the server that it is attached too, it shows the folder and file hierarchy for what it contains? And you want to merge all of them to be displayed into one page?

Well.. the way I'm hoping it can work is...

 

When I go to http://site.com/things it produces a page with a page full of directories. These directories are pulled from a different server, and displayed on one page instead of multiples. 

 

Does that make sense?

Link to post
Share on other sites
  • 0
Jack W
6 minutes ago, BinaryData said:

Well.. the way I'm hoping it can work is...

 

When I go to http://site.com/things it produces a page with a page full of directories. These directories are pulled from a different server, and displayed on one page instead of multiples. 

 

Does that make sense?

I believe so. I mainly work with PHP + Apache servers, so I'm looking at the pre-generated folder structure it displays if there is no index.php/html (default page).

 

The way I would possibly do it... assuming each server has PHP/Apache installed and all files are located inside the www directory, that you want to show, is to use PHP's scandir function.

 

Documentation: http://php.net/manual/en/function.scandir.php

 

What you could do there is, quite simply, on each server, create a file in the www (web root) called something like "get_files.php", then include the following:

 

<?php
$dir    = '/where/my/files/are/located';
$files = scandir($dir);

print_r($files);
?>

This would output an 'array', such as:

 

(
    [0] => .
    [1] => ..
    [2] => bar.php
    [3] => foo.txt
    [4] => somedir
)

Which would list all the files/folders found.

 

If you wanted to clean that up a bit, to customise how it displays what it has found, you would need to parse the array in some way, like:

 

<?php
	foreach ($files as $file) {
		echo '<b>' . $file[1] . '</b>';
	}
?>

This would display the file name/folder name as bold.

 

Then, where you want to display ALL of the files together, you'd create a "display_files.php" on the server where you want to display all the files and include the get_files.php files, e.g:

 

<?php
echo "server 1's files";
include_once('http://server1/get_files.php');
echo "server 2's files";
include_once('http://server1/get_files.php');
echo "server 3's files";
include_once('http://server2/get_files.php');

echo "<br><br>Completed. All files have been listed.";
?>

Then you'd visit, e.g http://mydisplayserver/display_files.php and it would show all the files.

 

Note: I haven't tested any of the code I've written here... but this should definitely put you on the right track (assuming I understand what you want).

Another note: This isn't secure. You should not display all files on a server openly without any type of authentication. I recommend, at the very least, you enable HTTP Authentication on these files.

Link to post
Share on other sites
  • 0
BinaryData

Well, the files aren't exactly in /www. They are in a different folder that I've remapped using A Index's (BudMan did this for me). So the "location" would be something like "http://ddl.neowin.net".

 

I guess what I'm thinking is; have an index.php file that pulls the list, generates the DDL Links, and then the "Main Server" would post that list with the rest of the files.

Link to post
Share on other sites
  • 0
Jack W
2 minutes ago, BinaryData said:

Well, the files aren't exactly in /www. They are in a different folder that I've remapped using A Index's (BudMan did this for me). So the "location" would be something like "http://ddl.neowin.net".

 

I guess what I'm thinking is; have an index.php file that pulls the list, generates the DDL Links, and then the "Main Server" would post that list with the rest of the files.

The same code can work for any directory underneath www. Assuming your subdomain's directory is located inside www, e.g /www/ddl/ then you can just do the same code but add /ddl/ to the paths. Or just put it into the root www of each subdomain and link to it directly, again, same code.

Link to post
Share on other sites
This topic is now closed to further replies.
  • Recently Browsing   0 members

    No registered users viewing this page.