content top

Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration

Recently I worked on Youtube API for one of my Websites. The task was that  user will enter the youtube video URL in a text box and while clicking on a button I have to display the video details. I used file_get_contents() for getting the youtube feed entry of the video.
It was working fine in my local and and when I hosted in server, I got the following error.

Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in XXXX.php on line XX
My server configuration is not allowing me to use the method file_get_contents().

The solution : Use curl.

I just added the following function to my page

function curl_get_contents ($url) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_URL, $url);
$html = curl_exec($curl);
curl_close($curl);
return $html;
}

And replaced file_get_contents($url) with curl_get_contents($url)

Now its working smoothly :)

Note:If you are using WAMP,  by default curl is not enabled.  So you can check this link to  enable curl in wamp)

Blog Widget by LinkWithin

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment