SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Oct 2013
    0 Post(s)
    0 Thread(s)

    Unhappy File_get_content IS throwing me errors

    I'm trying to get the script to connect to a txt file, open it, get first line of text in txt file, then turn it into a variable, once it has the variable $url it is then placed into the file_get_content(), the finish product should then shoots out onto the page. My host allows fopen content so it can't be that. The url is correct as I tested with typing it in fully in file_get_content but if it's a variable in it's place like file_get_conent($url) I get this error. Perhaps it's adding something when I fetch the first line in the file I really don't see how since it's a text file and I haven't added anything else except three lines of text.

    The Error:
    Warning: file_get_contents(http://some_web_url.php ) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in

    PHP Code:
     // opens temp data file
    $fetch_url file('');
    // fetches first line: $fetch_url[0];
    $url $fetch_url[0]; 

    $file_string file_get_contents($url); 
    I just don't understand why this darn thing an't workin.

  2. #2
    SitePoint Evangelist
    Join Date
    Aug 2006
    Nantwich, Cheshire
    2 Post(s)
    0 Thread(s)
    Have you examined the contents of $url to see whether it is as you expect? Also I note that if the url contains any 'special' characters it must be encoded, though I assume you'd have had the same problem when you typed it directly. Can you show the contents of the file here? - my homage to a car from the 1970s

  3. #3
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Knoxville TN
    66 Post(s)
    0 Thread(s)
    A common security setting prevents the fopen family of functions (of which file_get_contents is a member) from opening remote files. It is advised that you leave the setting alone and use cURL.

    Here's information on the setting.

    You have been warned.


Posting Permissions

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