2

When I use function getimagesize or imagecreatefromjpeg for a link in my app it send me an error:

getimagesize(): php_network_getaddresses: getaddrinfo failed: Name or service not known

Here is my code:

         // tidy up by removing temporary image
            unlink($tempname);
             return $retvars;
         }

         /**
          * Extract info from a JPEG file without using the GD library.
          * @param $file (string) image file to parse
          * @return array structure containing the image data
          * @public static
          */
         public static function _parsejpeg($file) {
             $a = getimagesize($file);
             if (empty($a)) {
                 //Missing or incorrect image file
                 return false;
             }
             if ($a[2] != 2) {
                 // Not a JPEG file
                 return false;
             }
             // bits per pixel
             $bpc = isset($a['bits']) ? intval($a['bits']) : 8;
             // number of image channels
             if (!isset($a['channels'])) {

Exactly when i copy the link of image in my address bar it appear and it exist. My PHP version is 5.3.3.

halfer
  • 19,824
  • 17
  • 99
  • 186
ali abdzad
  • 130
  • 1
  • 10
  • Would you mind pasting in your code, and your error message, as text? Use the 'code' button for the first and the 'quote' button for the second. An image is not suitable here: text as images cannot be read by search engines, and it is not accessible for sight impaired users either. – halfer Aug 10 '14 at 09:03
  • ok , i've do that @halfer – ali abdzad Aug 10 '14 at 09:46
  • This has nothing to do with Yii – Imre L Aug 10 '14 at 10:07
  • 1
    Are you trying to access hotlinked picture? What is value of `$file`? – Imre L Aug 10 '14 at 10:09
  • 1
    You are reading a file from a URL. I think that should work, but you could always try reading it with `file_get_contents`, copy it to a temp file, and then use `getimagesize` on it from there. – halfer Aug 10 '14 at 10:14

1 Answers1

0

It does not matter if that picture is in your app or another place on the web because you are using the image URL. The error also is related to getting some contents from the web which is better to be handled by curl.

What you need to do is using the image address from your file system instead.

Soheil
  • 1,201
  • 2
  • 11
  • 18