Normac Posted April 2, 2008 Share Posted April 2, 2008 Right got the post wrote down now main.php: include ('function.php'); $linkss=file(something.txt'); foreach ($linkss as $line_num => $link) { $pieces = explode('/', $link); linkgetter($link, "links.txt", ""); something.txt format: http://www.example.com/page/1.html http://www.example.com/page/2.html http://www.example.com/page/3.html Important linkgetter code: function linkgetter($url, $filename, $testinternal) { $fh=fopen('something.txt', 'w') or die(); $output = file_get_contents($url, "r"); //do stuff with output $cat="$cat\n"; } All that Function.php just includes the linkgetter function. The linkgetter function just gets some links (I'm tracking backlinks and checking if they still work) and prints some info. Now I'm using PHP 4 on a local sever, though the websites are online. Every loop I get the following error message. Warning: file_get_contents(http://www.example.com/page/1.html ) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\scraper\function.php on line 7 If i replace $url with $output = file_get_contents(http://www.example.com/page/1.html, "r"); it works. (The Page exists.) So what am I doing wrong? Link to comment https://forums.phpfreaks.com/topic/99266-solved-file_get_contents-404-error/ Share on other sites More sharing options...
discomatt Posted April 2, 2008 Share Posted April 2, 2008 You're missing an opening quote. $linkss=file(something.txt'); should be $linkss=file('something.txt'); Link to comment https://forums.phpfreaks.com/topic/99266-solved-file_get_contents-404-error/#findComment-507893 Share on other sites More sharing options...
trq Posted April 2, 2008 Share Posted April 2, 2008 If i replace $url with $output = file_get_contents(http://www.example.com/page/1.html, "r"); it works. I don't see where you use $url in your code. Anyway, are url_wrappers enabled? Link to comment https://forums.phpfreaks.com/topic/99266-solved-file_get_contents-404-error/#findComment-507895 Share on other sites More sharing options...
Normac Posted April 2, 2008 Author Share Posted April 2, 2008 You're missing an opening quote. $linkss=file(something.txt'); should be $linkss=file('something.txt'); Yea I changed the filename for viewing here, accedently deleted a ' . If i replace $url with $output = file_get_contents(http://www.example.com/page/1.html, "r"); it works. I don't see where you use $url in your code. Anyway, are url_wrappers enabled? It is there: function linkgetter([b]$url[/b], $filename, $testinternal) { $fh=fopen('something.txt', 'w') or die(); $output = file_get_contents([b]$url[/b], "r"); //do stuff with output $cat="$cat\n"; } $linkss=file(something.txt'); foreach ($linkss as $line_num => $link) { $pieces = explode('/', $link); linkgetter([b]$link[/b], "links.txt", ""); Basicly it takes lists of links from a txt file, then takes the pages to check for certain info. Link to comment https://forums.phpfreaks.com/topic/99266-solved-file_get_contents-404-error/#findComment-507916 Share on other sites More sharing options...
trq Posted April 2, 2008 Share Posted April 2, 2008 So, the problem would seen to be that you do not have enable allow_url_fopen enabled in your php.ini or that the filepath you are passing to file_get_contents does not exist. Link to comment https://forums.phpfreaks.com/topic/99266-solved-file_get_contents-404-error/#findComment-507923 Share on other sites More sharing options...
Normac Posted April 2, 2008 Author Share Posted April 2, 2008 Really stupid mistake, forgot to trim the $linkss variable. Fixed and solves, thanks all Link to comment https://forums.phpfreaks.com/topic/99266-solved-file_get_contents-404-error/#findComment-507961 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.