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: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 overUnable to find the wrapper - did you forget to enable it when you configured PHP?
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
Yii Framework 2.0 Login with User Database
Order Properties Should Not Be Accessed Directly - Woocommerce 3.0
What Are Available Solutions of a Browser/Mobile Phone Detection
How to Require PHP Files Relatively (At Different Directory Levels)
Object Copy Versus Clone in PHP
Paypal Ipn Bad Request 400 Error
How to Use PHPize After Update to MACos Mojave
How to Retrieve Date from Table Cell Using PHPspreadsheet
Number in the Top-Level Domain
Type Hinting: Default Parameters
Get the Get Variables from a Url String
Use PHP to Check If Page Was Accessed with Ssl
How to Create a PHP Function That I Can Call Without Parentheses
How to Deal with "Method Not Found in Class" Warning for Magically Implemented Methods