File_Get_Contents() Failed to Open Stream:

file_get_contents() how to fix error Failed to open stream, No such file

The URL is missing the protocol information. PHP thinks it is a filesystem path and tries to access the file at the specified location. However, the location doesn't actually exist in your filesystem and an error is thrown.

You'll need to add http or https at the beginning of the URL you're trying to get the contents from:

$json = json_decode(file_get_contents('http://...'));

As for the following error:

Unable to find the wrapper - did you forget to enable it when you configured PHP?

Your Apache installation probably wasn't compiled with SSL support. You could manually try to install OpenSSL and use it, or use cURL. I personally prefer cURL over file_get_contents(). Here's a function you can use:

function curl_get_contents($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}

Usage:

$url = 'https://...';
$json = json_decode(curl_get_contents($url));

Warning: file_get_contents failed to open stream: No such file or directory?

Try string like this it may help

Just use . for concatenating.

$localFile='/var/www/uploads/$file_name';

to

$localFile='/var/www/uploads/'.$file_name;

and

$remoteFile='/home/nsadmin/$file_name';

to

 $remoteFile='/home/nsadmin/'.$file_name;

file_get_content: failed to open stream: No such file or directory

It's possible the web server doesn't have permissions to access that user's files. If you move the file to an accessible or shared location it may work. (You can also change permissions to permit access, however doing that on the user's personal directory is not advisable since it could expose other information to unauthorized users.)

file_get_contents - failed to open stream: HTTP request failed

The problem is that your url is read literally due to '.

If you use " then the variables in the string will be used as variables but now your string is '...apikey=$api' instead of '...apikey=sdflsdksdksdsdskd'

So change the line

$json_url = file_get_contents('https://api.sandbox.amadeus.com/v1.2/flights/low-fare-search?origin=$origin&destination=$destination&departure_date=$departure_date&return_date=$return_date&number_of_results=$number_of_results&apikey=$apikey');

To

$json_url = file_get_contents("https://api.sandbox.amadeus.com/v1.2/flights/low-fare-search?origin=$origin&destination=$destination&departure_date=$departure_date&return_date=$return_date&number_of_results=$number_of_results&apikey=$apikey");


Related Topics



Leave a reply



Submit