1

Right now my code is below.Which I believe sends two request to Image url

if(getimagesize($imgurl)) // request 1
{

$imgget = file_get_contents("$imgurl"); // request 1
//other operations done here..
}

how can I check if its valid image and If its valid image get its contents in single request.

i.e., something like below

 if($imgget = getimagesize($imgurl)) // request 1
    {

    //$imgget must have image contents  

    }
Vishnu
  • 2,372
  • 6
  • 36
  • 58
  • there's an answer here http://stackoverflow.com/questions/676949/best-way-to-determine-if-a-url-is-an-image-in-php – JoulinRouge Nov 05 '15 at 15:00
  • @JoulinRouge that just detects if its image..my question is different – Vishnu Nov 05 '15 at 15:01
  • sorry! However there are no other checks needed: as stated in the documentation: "Some formats may contain no image or may contain multiple images. In these cases, getimagesize() might not be able to properly determine the image size. getimagesize() will return zero for width and height in these cases." http://php.net/manual/en/function.getimagesize.php – JoulinRouge Nov 05 '15 at 15:03
  • Curl is the answer to this question. https://m.youtube.com/watch?v=hMpCsfvi_3c – Panda Nov 05 '15 at 15:04
  • 1
    @JoulinRouge Its not about checking if its image.. actually getimagesize() download full image in order to check if its image..I wanna know if I can get the image content with one request – Vishnu Nov 05 '15 at 15:06
  • 1
    you can do smething like this: $img = '/my/folder/image.gif'; file_put_contents($img, file_get_contents($imgurl)); and then check if image.gif is a proper image – JoulinRouge Nov 05 '15 at 15:13
  • seems like good idea joulinrouge.. can you answer..so i can accept – Vishnu Nov 07 '15 at 15:08

0 Answers0