PDA

Click to See Complete Forum and Search --> : Read File Problem


lintz
Apr 11th, 2006, 06:56 PM
I'm trying to read a txt file from another site but no matter what I try I get the below error.

Warning: fopen(http://www.mysite.com/files/myfile.txt): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request

This is the code I've tried....

$handle = fopen("http://www.mysite.com/files/myfile.txt", "r");

and

$handle = file('http://www.mysite.com/files/myfile.txt');

uainfantry
Apr 13th, 2006, 07:47 PM
Why not use include?

Inuyasha1782
Apr 14th, 2006, 12:17 AM
Er, I don't think those commands support opening files outside of the server. Is that what you are trying to do? If not, then don't include the "http://www.mysite.com/" in there, simply just include "/files....".

lintz
Apr 14th, 2006, 01:12 AM
uainfantry, can I use include for a file on another website?

eg. my site = www.mysite1.com

file i want resides on www.mysite2.com

uainfantry
Apr 14th, 2006, 01:18 AM
Yea, it will load the file into a table or whatever you want to load into.

include('http://www.mysite2.com/index.html')

penagate
Apr 14th, 2006, 02:12 AM
Include is not the same as fopen(). To use the file functions across HTTP you need to set allow_url_fopen = 1 in php.ini. If you are getting a bad request error then try accessing it through the browser, it may be a misconfiguration on the remote server.