PHP Ini File_Get_Contents External Url

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



Leave a reply



Submit