If you are using Windows and a server like Wamp or Xampp, there are also some bugs that are in combination of Windows, file_get_contents() and localhost that are not going to be fixed. Use cURL
instead. file_get_contents has some php.ini values set off by default.
Use cURL. Off course you have to enable it if its not enabled but it most probably is.
$file_path_str = "http://localhost/pathtofile";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, ''.$file_path_str.'');
curl_setopt($ch, CURLOPT_HTTPGET, 1);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_USERAGENT, sprintf("Mozilla/%d.0",rand(4,5)));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$curl_response_res = curl_exec ($ch);
Also remember, Apache in Windows by default can't access files outside www or htdocs folder.