In the following code i get error failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request
$url = "https://graph.facebook.com/$orderId";
$url_with_token = $url . "?access_token=$token";
$result= json_decode(file_get_contents($url_with_token));
Please let me know where I am going wrong
Just add two lines in your php.ini file.
extension=php_openssl.dll
allow_url_include = On
its working for me.
Related
When I try to get the size of an image it returns false and I receive this warning:
$img_size = getimagesize($img_dir.$image_name.'0.jpg');
var_dump($img_size); // returns bool false
Warning:
getimagesize(http://example.com/wp-content/uploads/2018/devices/mk10_0.jpg):
failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request
in
My first thought was the path to the image was incorrect but I tried the url in an image tag and it loaded the image just fine
echo '<img src="'.$img_dir.$image_name.'0.jpg" alt="">';
I don't know if it would be relevant to this question but before I received this warning I was having issues with the same line of code with how PHP was setup, I had to update my php.ini variable allow_url_fopen=1
Could there be more to do on my PHP setup?
EDIT
This code doesn't solve the problem but is an alternate way to get the image size information without throwing an error / waring.
$img_data = file_get_contents($img_path.$image_name.'0.jpg');
$size = getimagesizefromstring($img_data);
i want to print/echo a file that's save on my server and have a specific URL and try this below code to read
$lines = file($files['file_path']);
foreach ($lines as $line_num => $line) {
echo htmlspecialchars($line) . "<br />\n";
}
but it returned the following error :
file(http://myweburl/uploads/files/1506514901_txt.txt): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
and i also try fgets with fopen function that return same error
i also follow How to read a file line by line in php but don't get any solutions
while above function is working on localhost but not server
please help
Try to enable :
allow_url_fopen = on
in php.ini file on your server
i am using yahoo finance API where i call an API and that gives me a CSV file. below are my codes.
$handle = fopen('http://download.finance.yahoo.com/d/quotes.csv?s=INFY&f=l1c1va2xj1b4j4dyekjm3m4rr5p5p6s7n=.csv', "r");
while execute this line it throws an warning that is
failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request
i have spend more time on google but no result yet.
but sometimes its working fine without throwing any warning.
another things it also working fine in local. there is no working throw while execute
if anyone knows the exact solution please help me.
Thanks
Sanjib
I am trying to display rss feeds for this link. http://vuconnect.com/controls/cms_v2/components/rss/rss.aspx?sid=1643&gid=2&calcid=664&page_id=13
But it is showing this error
Warning:
simplexml_load_file(http://vuconnect.com/controls/cms_v2/components/rss/rss.aspx?sid=1643&gid=2&calcid=664&page_id=13):
failed to open stream: HTTP request failed! in
G:\wamp\www\scripts\rss_feeds\demo-1.php on line 48
Here is the code i am using.
$url = 'http://vuconnect.com/controls/cms_v2/components/rss/rss.aspx?sid=1643&gid=2&calcid=664&page_id=13';
$xml = simplexml_load_file($url);
echo '<pre>';
print_r($xml->channel);
die;
?>
needs allow_url_fopen to be On.
Check you php.ini and change it to On, if it is Off.
I hope this solves your problem
I'm trying to create a simple script to fetch user profile data from an id.
For example
$link = json_decode(file_get_contents('http://graph.facebook.com/zuck'));
echo $link_>name;
The problem is that it's seems like facebook is limiting these kind of requests. Sometimes it's working, but sometimes I'm getting the following error :
Warning: file_get_contents(http://graph.facebook.com/zuck)
[function.file-get-contents]: failed to open stream: HTTP request
failed! HTTP/1.0 403 Forbidden
Try to use curl instead of file_get_contents and use curl_error to see why it returns 403. There's a request limit that you might reach and that might be the cause why it gives you 403.