Saravana
Saravana

Reputation: 3496

Warning: file_get_contents(): https:// wrapper is disabled in the server configuration by all

When I am upload a csv file with zipcode it will convert and save a latitude and logitude. The error occurring a convert a zipcode to lat,lng. In my localhost its working fine. When I am uploading in a live server. I am getting this error Warning: file_get_contents(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /hermes/bosnaweb05a/b1410/ipg.rwdinfotechcom/vw/zipmapping/index.php on line 29 . I have checked my google api key also. I can't able add php.ini file. If I upload php.ini file its shows internal server error.

Here my code
function getLnt($zip){
$url = "https://maps.googleapis.com/maps/api/geocode/json?key=AIzaSyDEGgYDar8y3Bx-1FpY3hq6ON4LufoRK60&address=
".urlencode($zip)."&sensor=false";

$result_string = file_get_contents($url);
$result = json_decode($result_string, true);

$result1[]=$result['results'][0];
$result2[]=$result1[0]['geometry'];
$result3[]=$result2[0]['location'];
return $result3[0];
}

Upvotes: 44

Views: 137419

Answers (8)

Samuel Olubayo
Samuel Olubayo

Reputation: 305

If you are getting this error while you're trying to install a package on cpanel terminal. you can get past the error with the command below:

php -d allow_url_fopen=1 $(which composer) require srmklive/paypal

Upvotes: 0

Alex
Alex

Reputation: 71

if need only once run script using CLI then just add -d allow_url_fopen=1, even if it disabled in main php.ini, example:

php -d allow_url_fopen=1 script.php

Upvotes: 0

Saravana
Saravana

Reputation: 3496

First, check your PHP file with this code and then enable the fopen in your php.ini file

<?php 
if( ini_get('allow_url_fopen') ) {
    die('allow_url_fopen is enabled. file_get_contents should work well');
} else {
    die('allow_url_fopen is disabled. file_get_contents would not work');
}

?>

Edit the php.ini file and enable using below code

allow_url_fopen = 1 //0 for Off and 1 for On Flag

Upvotes: 55

bocanegragcj
bocanegragcj

Reputation: 371

This solution worked for me as I couldn't access the php.ini file.

I added this function:

function curl_get_file_contents($URL)
{
    $c = curl_init();
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($c, CURLOPT_URL, $URL);
    $contents = curl_exec($c);
    curl_close($c);

    if ($contents) return $contents;
    else return FALSE;
}

and use it instead of

file_get_contents($url)

and it worked.

The solution is better explained here, all credits to the creator of the post.

Upvotes: 26

wkille
wkille

Reputation: 643

Try removing the lines below from .htaccess and switch to the latest version of PHP.

For me this was being caused by the following getting added to .htaccess:

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php70” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php70___lsphp .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

Removing it solved the problem but it reappeared after an unknown period of time.

I noticed I was running (deprecated) PHP 7.0 and I changed it to (latest version) 7.4. I sent a support ticket to our hosting provider about the problem and they responded with:

If you've selected PHP 7.4 now, it shouldn't replace those lines any longer, as that's what CloudLinux does - it forces the specific PHP version to be loaded via .htaccess

It's not come back in the last hour so fingers crossed.

Upvotes: 2

Prem Acharya
Prem Acharya

Reputation: 501

  1. Login to your Cpanel
  2. Under Software click on MultiPHP INI Editor demo
  3. Click on Editor Mode and select Domain demo
  4. Paste allow_url_fopen = 1 and save

Upvotes: 48

Pavel Rakowski
Pavel Rakowski

Reputation: 15

I had the same issue and I google this topic.
I could not update it from joomla direct 3.9.1 to 3.9.2 not even by uploading manually.
The reason was that before this update it forced me to upgrade php version to 7.2 so I did it from cpanel, now to solve next update will be this:

  1. Login to cpanel
  2. Find " MultiPHP INI Editor" under software
  3. Choose your domain and select edit
  4. Set :
    "max_execution_time " to 90 (it was in mine 30)
    "memory_limit" to 256M (it was by new php enabling 32M only !)
    "post_max_size" to 100M
    "upload_max_filesize" to 100M

...because every php new version is set to default.

Enjoy ;)

Upvotes: 1

Poiz
Poiz

Reputation: 7617

Try adding the Code below to your PHP File:

<?php
    ini_set("allow_url_fopen", 1);

The Problem could probably be that on the Server, the PHP Setting for allow_url_fopen may have been configured differently: 0 for example. You could also do the same in your php.ini File if you have access to it.

Hope this helps....

Upvotes: -2

Related Questions