2016-05-26 1 views
0

Я показываю изображение из файла с помощью PHP. Мой код выглядит следующим образомПроверить файл пустой imagecreatefromgif - php

$image = @imagecreatefromgif(../ProfileIcons/".$use); 

$text_color = imagecolorallocate($image, $r, $g, $b); 
imagestring($image,$font_size,14,4, $code, $text_color); 

header('Content-Type: image/gif'); 
$kk = imagegif($image); 

imagedestroy($image); 

Вот как я проверить, если изображение присутствует в ProfileIcons/ пусто?

я должен поставить условие, что такое

if (image is present in `ProfileIcons/`) 

    $image = @imagecreatefromgif(../ProfileIcons/".$use); 

else (image is not present in the folder) 

    $image = Show default image 

Как этого добиться?

ответ

2

попытка смотреть в file_exists

if (file_exists($filePath)) { 
// process image 
} else { 
// use default image 
} 
0
// check if file exist 
    if(file_exists('../ProfileIcons/'.$use.'')) 
    {// do what you like }else{//} 
Смежные вопросы