• 0

[PHP] Pulling from multiple sources


Question

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 comment
https://www.neowin.net/forum/topic/1282336-php-pulling-from-multiple-sources/
Share on other sites

9 answers to this question

Recommended Posts

  • 0
  On 19/12/2015 at 11:19, Nik L said:

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

Expand  

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

  • 0

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.

  • 0
  On 19/12/2015 at 11:30, 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.

Expand  

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

  • 0

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?

  • 0
  On 27/12/2015 at 13:30, 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?

Expand  

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?

  • 0
  On 27/12/2015 at 13:33, 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?

Expand  

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.

  • 0

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.

  • 0
  On 27/12/2015 at 14:07, 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.

Expand  

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.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • That’s why I love classic Notepad from W10 IOT LTSC. It opens up instantly, uses very little resources, is just a plain notepad and nothing more. the title should be notepad has lost focus.
    • Seeing my profile picture in Notepad creeped me out. I do not appreciate that Copilot is opt-out rather than opt-in. I don't want Notepad to have connectivity. The other improvements are fine, including the upcoming Markdown support (although I hate Markdown's handling of newlines with a passion).
    • More like Trelane: https://memory-alpha.fandom.com/wiki/Trelane But, yes, Q.  
    • This would come in handy to me as an Uber driver. My biggest pet peeve is when passengers listen to their own audio on their phones without using headphones when they can hear I'm already playing music through my car's head unit.
    • Astonishing new tech could kill headphones forever as it bends sound right into ears by Sayan Sen Imagine being able to listen to your favorite song or podcast out loud without disturbing anyone nearby even without wearing headphones. That’s what a team at Penn State University has been working on. Led by acoustics professor Yun Jing, they’ve come up with a clever way to create invisible audio zones called “audible enclaves” where sound can be heard only at one exact spot. They use ultrasound, which is normally inaudible to people, along with something called acoustic metasurfaces—tiny lenses that can bend sound in specific directions. By combining two ultrasound beams that travel in curved paths and meet at a single point, they’re able to make sound audible only at that intersection. As Jing explained, “The person standing at that point can hear sound, while anyone standing nearby would not. This creates a privacy barrier between people for private listening.” To make this happen, the system includes two ultrasonic speakers and the metasurface lenses, which were 3D printed by Xiaoxing Xia from Lawrence Livermore National Lab. Each beam has a slightly different frequency, and when they meet, a local reaction makes the sound audible. Neither beam is loud on its own—the sound only forms at that shared point. Jia-Xin “Jay” Zhong, one of the researchers, shared how they tested the idea: “We used a simulated head and torso dummy with microphones inside its ears to mimic what a human being hears at points along the ultrasonic beam trajectory, as well as a third microphone to scan the area of intersection. We confirmed that sound was not audible except at the point of intersection, which creates what we call an enclave.” One of the biggest advantages of their approach is that it works across a wide range of sound frequencies—between 125 Hz and 4 kHz, which covers most of what people can hears. Even in rooms where sound usually bounces around, their system held up well. And it’s surprisingly compact too: the whole setup measures about 16 centimeters, roughly the size of a pencil case. “We essentially created a virtual headset,” Zhong said. In practice, it means that someone standing in the audible enclave can hear what’s being played clearly, while everyone else around hears nothing at all. That could be especially useful in shared spaces like cars, classrooms, or open offices. Right now, the sound can travel about one meter and hits around 60 decibels which is similar to regular talking volume. The team believes they can push those limits further by using stronger ultrasound. All this might seem futuristic, but it’s grounded in solving a basic problem: how to direct sound only where it’s needed. If you’re into tech and sound design, this could open up a whole new world of personalized audio experiences. Source: Penn State, PNAS | Image via Depositphotos This article was generated with some help from AI and reviewed by an editor. Under Section 107 of the Copyright Act 1976, this material is used for the purpose of news reporting. Fair use is a use permitted by copyright statute that might otherwise be infringing.
  • Recent Achievements

    • First Post
      leoniDAM earned a badge
      First Post
    • Reacting Well
      Ian_ earned a badge
      Reacting Well
    • One Month Later
      Ian_ earned a badge
      One Month Later
    • Dedicated
      MacDaddyAz earned a badge
      Dedicated
    • Explorer
      cekicen went up a rank
      Explorer
  • Popular Contributors

    1. 1
      +primortal
      503
    2. 2
      ATLien_0
      211
    3. 3
      Michael Scrip
      197
    4. 4
      Xenon
      149
    5. 5
      +FloatingFatMan
      125
  • Tell a friend

    Love Neowin? Tell a friend!