SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Oct 2013
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    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('http://website.com/example.txt');
    // 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 Addict
    Join Date
    Aug 2006
    Location
    Nantwich, Cheshire
    Posts
    278
    Mentioned
    1 Post(s)
    Tagged
    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?
    http://www.firenza.net - my homage to a car from the 1970s

  3. #3
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,011
    Mentioned
    56 Post(s)
    Tagged
    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.

    http://php.net/manual/en/filesystem.configuration.php

    You have been warned.


Bookmarks

Posting Permissions

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