1

I have some issues on my server in running getimagesize on remote url images.

For example if I run this code on my local server it works fine and returns OK:

<?php
$file = 'http://inspiring-photography.com/wp-content/uploads/2012/04/Culla-bay-rock-formations-Isle-of-Uist.jpg';
$pic_size = getimagesize($file);
if (empty($pic_size))
{
    die('FALSE');
}
die('OK');

?>

But if I run the same code on my server I cannot make it work properly. Can you help in determining which settings shall I ask to enable?

I think some of these may be involved:

  1. mod_security
  2. safe_mode
  3. allow_url_fopen

Can you help me in determining the right configuration to get this solved?

Thank you very much in advance.

Mighty Gorgon
  • 33
  • 1
  • 5
  • @RiggsFolly Sorry, what? *my server I cannot make it work properly* The server probably blocks accesses to other websites. You should enable error reporting in order to show us a real error message. – A.L May 30 '16 at 17:44
  • 2
    When you ask a question about an error, **ALWAYS** post the error log. To enable error reporting to your php code, append `error_reporting(E_ALL); ini_set('display_errors', '1');` at the top of your script, what does it return ? – Pedro Lobito May 30 '16 at 17:44
  • sounds like the manual was either not read, not understood, or not followed to the letter. – Funk Forty Niner May 30 '16 at 17:47
  • @A.L I have enabled error_reporting, but I don't get any error, getimagesize doesn't return any error. – Mighty Gorgon May 30 '16 at 20:57
  • @PedroLobito I have enabled error_reporting, but I don't get any error, getimagesize doesn't return any error. – Mighty Gorgon May 30 '16 at 20:57

2 Answers2

7

allow_url_fopen is off. Either enable it on your php.ini, or use curl to get the image:

function getImg($url){
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $data = curl_exec($curl);
    curl_close($curl);
    return $data;
}

$url = "http://inspiring-photography.com/wp-content/uploads/2012/04/Culla-bay-rock-formations-Isle-of-Uist.jpg";
$raw = getImg($url);
$im = imagecreatefromstring($raw);
$width = imagesx($im);
$height = imagesy($im);
echo $width." x ".$height;

SRC

Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268
  • 1
    Thank you very much @Pedro Lobito for your help, much appreciated. As stated above allow_url_fopen is enabled, anyway my help desk was able to solve by disabling safe_mode and disable Apache mod_security as well. – Mighty Gorgon May 30 '16 at 21:06
3

You have to turn allow_url_fopen on in your php.ini file in order to allow it to access resources that are not local.

This is specified in the official document of getimagesize in the description of the filename parameter.

AntoineB
  • 4,535
  • 5
  • 28
  • 61
  • allow_url_fopen is enabled, anyway my help desk was able to solve by disabling safe_mode and disable Apache mod_security as well. – Mighty Gorgon May 30 '16 at 21:05