pass a txt file over a network through http protocol

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
momukhtar
Forum Newbie
Posts: 11
Joined: Thu Mar 06, 2008 8:02 pm

pass a txt file over a network through http protocol

Post by momukhtar »

Hi

I want to pass a txt file using http from Apache server to another webserver. I searched php documentation and found the "http_send_file" function but it does not take any url like webserver root and desired folder where i want to send a file. Any help as to which function I shall use.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: pass a txt file over a network through http protocol

Post by VladSun »

Could you explain the general purpose you are trying to achieve?
There are 10 types of people in this world, those who understand binary and those who don't
momukhtar
Forum Newbie
Posts: 11
Joined: Thu Mar 06, 2008 8:02 pm

Re: pass a txt file over a network through http protocol

Post by momukhtar »

The text file is generated in Apache server hosting php. I want to pass that txt file to another webserver which can process it.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: pass a txt file over a network through http protocol

Post by VladSun »

You may use fopen()
There are 10 types of people in this world, those who understand binary and those who don't
whiterabbit
Forum Newbie
Posts: 14
Joined: Thu May 22, 2008 6:58 pm

Re: pass a txt file over a network through http protocol

Post by whiterabbit »

User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Re: pass a txt file over a network through http protocol

Post by panic! »

a very simplistic solution

server one where the text file is stored

<?

$file_contents=file_get_contents('somefile.txt');

// might wanna encode $file_contents somehow here.

file_get_contents('http://someotherserver.com/saveText.php ... e_contents);

?>

on server two where you're saving the text file to call this saveText.php

<?
$file_contents=$_GET['text']);

// might wanna decode here ...


file_put_contents('somefile.txt, $file_contents);

?>
momukhtar
Forum Newbie
Posts: 11
Joined: Thu Mar 06, 2008 8:02 pm

Re: pass a txt file over a network through http protocol

Post by momukhtar »

Can I use http_put_file and just pass the url of second server and filename.

$response = http_put_file("http://localhost/savefile.cgi", filename);
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Re: pass a txt file over a network through http protocol

Post by panic! »

yeah, if the file is accessible over http.
Post Reply