PHP ini file_get_contents external url
The setting you are looking for is allow_url_fopen
.
You have two ways of getting around it without changing php.ini, one of them is to use fsockopen()
, and the other is to use cURL.
I recommend using cURL over file_get_contents()
anyways, since it was built for this.
file_get_contents request to external site
Just use the https url instead of the http url:
https://spotifycharts.com/api/?type=regional&country=nl&recurrence=daily&date=latest&limit=200
How to use the current php page URL as a reference for an external image?
First change the link from
www.myserver.com/script.php/imageurl="www.otherserver.com/image.png"
TO
www.myserver.com/script.php?imageurl="www.otherserver.com/image.png"
You can download an image like so:
SOURCE
If you have allow_url_fopen
set to true:
$url = 'http://example.com/image.php';
$img = '/my/folder/flower.gif';
file_put_contents($img, file_get_contents($url));
OR
copy('http://example.com/image.php', 'local/folder/flower.jpg');
Else use cURL:
$ch = curl_init('http://example.com/image.php');
$fp = fopen('/my/folder/flower.gif', 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
URL not executed in file_get_contents();
I resolved out the solution there was a gap in URL there was space after api_key and extra_data not encoded, btw thanks for support.
.PHP
$url="http://www.foo.in/bound/bound.php?phone_no=".$from_id."&api_key=xxxxxxxxxxxxxxxxxxxxx=2&extra_data=".urlencode("<response><dial record='true' limittime='1000' timeout='30' moh='default' >".$to_id."</dial></response>");
$data = file_get_contents($url);
echo $data;
file_get_contents() of external resource may going out time?
You can set your own timeout using this:
ini_set('default_socket_timeout', 300); // 5 minutes
Related Topics
Difference Between Public, Private, and Protected
How to Create Friendly Url in PHP
Using Braces With Dynamic Variable Names in PHP
Why Check Both Isset() and !Empty()
How Can One Use Multi Threading in PHP Applications
Formatting a Number With Leading Zeros in PHP
How to Secure Database Passwords in PHP
Split a Comma-Delimited String into an Array
When Should I Use 'Self' Over '$This'
How to Force File Download With PHP
How to Set Up File Permissions For Laravel
How to Hide Config Files from Direct Access
How to Prevent SQL Injection With Dynamic Tablenames
MySQLi Update Throwing Call to a Member Function Bind_Param() Error
Getting Visitors Country from Their Ip
Convert a PHP Script into a Stand-Alone Windows Executable
Preferred Method to Store PHP Arrays (Json_Encode VS Serialize)