Uploading a single file to multiple servers?
Moderator: General Moderators
Uploading a single file to multiple servers?
As in the subject line, the eventual goal is to upload a single file from the client to multiple servers all of which host the same receiver file (perhaps upload.php?). is there a way to code a form which generates an HTTP POST and sends it to a variable list of URLs stored in a string array?
as far as i can tell, the only way to get a valid POST from an HTML form is using a File input box. so far i haven't been able to figure out how to re-use the same value from that box or set the default value of a File field. as a result i haven't worked out a way to re-use a single File field to send the file to multiple servers.
are there alternative ways to generate a valid HTTP POST? i wouldn't think so since that would (i thought) require client-side functions to get attributes on the file to be uploaded. anyone have any advice on this one?
as far as i can tell, the only way to get a valid POST from an HTML form is using a File input box. so far i haven't been able to figure out how to re-use the same value from that box or set the default value of a File field. as a result i haven't worked out a way to re-use a single File field to send the file to multiple servers.
are there alternative ways to generate a valid HTTP POST? i wouldn't think so since that would (i thought) require client-side functions to get attributes on the file to be uploaded. anyone have any advice on this one?
Sounds like a job for the server rather than the client. I'm not sure of the exact answer, or even if replicating the form post is the answer, but http://dodds.net/~cardinal/sendtohost.txt might point you in the right direction. It basically 'fakes' a form post, so you could post to one server and have that server 'fake' the form post to the other servers. I might have got the wrong end of the stick but it sounds like a kludge for replication *shrug*
it will definitely have to be done by the server once the client uploads the file one time (thus providing enough information for the server to effectively POST to other servers). at this time i'm not entirely clear how that function works but i'll play around with it and see what i can figure out...
- launchcode
- Forum Contributor
- Posts: 401
- Joined: Tue May 11, 2004 7:32 pm
- Location: UK
- Contact:
You could approach this from the other angle - i.e. your client uploads the file once to one server which then in turn kicks off scripts on the other servers and they grab the file from that initial server - pass them the filename/id or similar and they can retrieve it via a standard fopen call as long as they know where to look.
Cheers,
Rich
Cheers,
Rich
thats actually probably a lot easier to code. the only thing i'm not really up on is using PHP to move files around on a server. a script could sit in the root of a server and be used to download the file in question but what do you actually use to move the downloaded file from the root to a specific subdir? i'm still learning file-handling in PHP so any help you could lend would be very appreciated 
- launchcode
- Forum Contributor
- Posts: 401
- Joined: Tue May 11, 2004 7:32 pm
- Location: UK
- Contact:
- launchcode
- Forum Contributor
- Posts: 401
- Joined: Tue May 11, 2004 7:32 pm
- Location: UK
- Contact:
move_uploaded_file() does pretty much what its name implies - it moves a file that the USER has uploaded. That's all. Nothing more.
So if you want Joe Bloggs sat at his browser to upload a file, and then for your script to all that file to be "downloaded" by your other servers - you need to move it somewhere accessible first, and that's where the move_uploaded_file function comes into play.
After that point the OTHER servers can either get the file via the FTP functions (which will work fine with your set-up) or via something like fopen().
So if you want Joe Bloggs sat at his browser to upload a file, and then for your script to all that file to be "downloaded" by your other servers - you need to move it somewhere accessible first, and that's where the move_uploaded_file function comes into play.
After that point the OTHER servers can either get the file via the FTP functions (which will work fine with your set-up) or via something like fopen().
what are you talking about? i guess we are suffering a breakdown of communications.
my basic upload script is done. it works just fine. i have a single PHP document which generates a dynamic form the user uses to specify the target directory and server and a receiving script which resides on each server and catches the uploaded file and a URL-passed parameter specifying the directory the uploaded file goes to. i was planning on using this to get the file to one of the servers on the array and then trigger a sequence of automated downloads by the other servers of the file.
that (the downloading part) is the portion of the code i am working on now, and as such i was thinking you meant i should use move_uploaded_file() in the process of the other servers downloading the file, which wouldn't work at all.
see, when you said "FTP" functions i assumed you meant somehow using file transfer protocol. i was under the impression that doing so required a server to be running some sort of FTP service. i assume now that when you say 'FTP" you don't mean functions which attempt to log-in to an FTP service and make use of it but instead PHP-based HTTP functions which move files around. is this correct?
also, to clarify, what i'm not certain about now is how i go about making a PHP script which resides at the root of a server and downloads a file from the internet and puts it into a specific sub-directory. i will do some more research on the matter...
one other question which is related but completely different:
is there a way for PHP to determine the current IP address or domain name for the server the script is running on? like if i have a script running on http://www.script1.com, is there a way to initialize a variable with a string containing either "www.script1.com" or the IP address assigned to that domain? being able to do this will make the automated file propogation script easier...
-EDIT- i found that using the function copy() seems to work just fine for downloading files, and it lets you specify the destination directory, so it should be perfect for my purposes...
my basic upload script is done. it works just fine. i have a single PHP document which generates a dynamic form the user uses to specify the target directory and server and a receiving script which resides on each server and catches the uploaded file and a URL-passed parameter specifying the directory the uploaded file goes to. i was planning on using this to get the file to one of the servers on the array and then trigger a sequence of automated downloads by the other servers of the file.
that (the downloading part) is the portion of the code i am working on now, and as such i was thinking you meant i should use move_uploaded_file() in the process of the other servers downloading the file, which wouldn't work at all.
see, when you said "FTP" functions i assumed you meant somehow using file transfer protocol. i was under the impression that doing so required a server to be running some sort of FTP service. i assume now that when you say 'FTP" you don't mean functions which attempt to log-in to an FTP service and make use of it but instead PHP-based HTTP functions which move files around. is this correct?
also, to clarify, what i'm not certain about now is how i go about making a PHP script which resides at the root of a server and downloads a file from the internet and puts it into a specific sub-directory. i will do some more research on the matter...
one other question which is related but completely different:
is there a way for PHP to determine the current IP address or domain name for the server the script is running on? like if i have a script running on http://www.script1.com, is there a way to initialize a variable with a string containing either "www.script1.com" or the IP address assigned to that domain? being able to do this will make the automated file propogation script easier...
-EDIT- i found that using the function copy() seems to work just fine for downloading files, and it lets you specify the destination directory, so it should be perfect for my purposes...
Last edited by SleepyP on Fri May 14, 2004 1:12 pm, edited 1 time in total.
- launchcode
- Forum Contributor
- Posts: 401
- Joined: Tue May 11, 2004 7:32 pm
- Location: UK
- Contact:
No, when I said FTP I meant FTP. If all the other servers have FTP access to the one with the file, there's no reason at all why it wouldn't work.
You cannot MOVE a file via HTTP. It is impossible. All you can do is request that file and you can do that via fopen() and then save it out locally.
The way I had imagined it working would quite simply be:
1) Client uploads file to Server A
2) Server A saves file to location within the web root
3) Server A activates download scripts on Servers B, C and D by simply calling the script on those servers via fopen.
4) Servers B,C & D in turn request the file from Server A via fopen (having been told where it lives with part 3 above) and save the file out locally.
It can't see it being any more complex than that.
As for obtaining the domain/IP of the server - sure, it's in the $_SERVER super global. Dump out phpinfo() on your server to see it (and loads of other useful stuff): <?php phpinfo(); ?> will do.
You cannot MOVE a file via HTTP. It is impossible. All you can do is request that file and you can do that via fopen() and then save it out locally.
The way I had imagined it working would quite simply be:
1) Client uploads file to Server A
2) Server A saves file to location within the web root
3) Server A activates download scripts on Servers B, C and D by simply calling the script on those servers via fopen.
4) Servers B,C & D in turn request the file from Server A via fopen (having been told where it lives with part 3 above) and save the file out locally.
It can't see it being any more complex than that.
As for obtaining the domain/IP of the server - sure, it's in the $_SERVER super global. Dump out phpinfo() on your server to see it (and loads of other useful stuff): <?php phpinfo(); ?> will do.
- launchcode
- Forum Contributor
- Posts: 401
- Joined: Tue May 11, 2004 7:32 pm
- Location: UK
- Contact:
for this project the specs are to use just PHP, so it's a little harder than normal i guess... anyways, i just wanted to post something i just learned:
the Copy() function works well for downloading a file from anywhere online to the local server, but it will fail unless you are careful about formatting the strings you feed it. the source string (if it is a URL) must be properly encoded, meaning all spaces replaced with %20, etc. however, the destination path must be exactly as the path exists on the server, meaning all spaces must be left as is, etc...
this minor detail messed me up for a good hour today.....
the Copy() function works well for downloading a file from anywhere online to the local server, but it will fail unless you are careful about formatting the strings you feed it. the source string (if it is a URL) must be properly encoded, meaning all spaces replaced with %20, etc. however, the destination path must be exactly as the path exists on the server, meaning all spaces must be left as is, etc...
this minor detail messed me up for a good hour today.....