Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Apr 2006
    Location
    Northbrook, IL
    Posts
    394
    Thanks
    8
    Thanked 6 Times in 6 Posts

    Question fopen + fread only gets part of a remote txt file : (

    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.

    PHP Code:
    $filename 'http://user:pass@mysite.com/testfile.txt';
    $ary_header get_headers($filename1);
    $filesize $ary_header['Content-Length'];
    $fh fopen($filename'r');
    $data fread($fh$filesize);
    fclose($fh);
    echo 
    $filesize "<br />";
    echo 
    strlen($data); 
    any ideas?
    Leon

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You could try using file_get_contents instead. I think I remember something about fread timing out.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder
    Join Date
    Apr 2006
    Location
    Northbrook, IL
    Posts
    394
    Thanks
    8
    Thanked 6 Times in 6 Posts
    this worked:

    PHP Code:
    $filedata file_get_contents('http://user:pass@mysite.com/testfile.txt');
    echo 
    $filedata
    i prefer 2 lines anyways

    thanks.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •