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 2 of 2
  1. #1
    New Coder
    Join Date
    Aug 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Ways to read a file from an external host

    Problem: to read a file http://somesite.com/example.txt
    I know a few ways to this but none would work for all circumstances.

    1.
    PHP Code:
    $file 'http://somesite.com/example.txt';
    $source file_get_contents($file); 
    It won't work on those hosts that allow_url_fopen not turn 'On'.

    2.
    PHP Code:
    $file 'http://somesite.com/example.txt';
    system('wget ' .$file' > temp.txt');
    $source file_get_contents($temp.txt); 
    or
    PHP Code:
    $file 'http://somesite.com/example.txt';
    system('curl ' .$file' > temp.txt');
    $source file_get_contents($temp.txt); 
    It won't work on those hosts that would not allow 'write permision' to a file.

    3.
    PHP Code:
    $file 'http://somesite.com/example.txt';
    $ch curl_init($file);
    curl_setopt($chCURLOPT_HEADER0);
    curl_setopt($chCURLOPT_POST1);
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
    $source curl_exec($ch);      
    curl_close($ch); 
    This won't work on those hosts that have no cURL extension installed.

    I run out of ways. Any hints would be appreciated. Thanks!
    --ngungo

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,549
    Thanks
    8
    Thanked 1,095 Times in 1,086 Posts
    Most webhosts I've used lately have "allow_url_fopen" disabled,
    and they specifically give instructions on using cURL.

    cURL is the preferred method.
    If not available, then switch to a different webhost.


  •  

    Posting Permissions

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