...

View Full Version : fopen + fread only gets part of a remote txt file : (



Leeoniya
06-11-2007, 06:58 AM
as the topic says, the following code returns 2 different things, the correct $filesize (9425) from the header and only part of the text file into $data (2491 bytes)

unfortunately, i cannot give out the user and pass. all i can say is that when i run it on my apache server locally, it reads the entire file properly. The split on the remote site occurs between the numbers 1 and 4 in "14", so i have no idea what trips it up.


$filename = 'http://user:pass@mysite.com/testfile.txt';
$ary_header = get_headers($filename, 1);
$filesize = $ary_header['Content-Length'];
$fh = fopen($filename, 'r');
$data = fread($fh, $filesize);
fclose($fh);
echo $filesize . "<br />";
echo strlen($data);

any ideas?
Leon

_Aerospace_Eng_
06-11-2007, 07:02 AM
You could try using file_get_contents instead. I think I remember something about fread timing out.

Leeoniya
06-11-2007, 07:14 AM
this worked:


$filedata = file_get_contents('http://user:pass@mysite.com/testfile.txt');
echo $filedata;

i prefer 2 lines anyways :)

thanks.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum