2010-07-29 6 views
3

사용자가 정적 GIF를 업로드 할 수 있지만 애니메이션을 업로드하지 못하게하고 싶다고 생각합니다. 아바타가 프로페셔널하고 산만 해 보이는 것처럼 말할 수 있습니다. PHP 또는 Zend Framework에서 파일 업로드의 유효성을 검사 할 수있는 방법이 있습니까?파일 업로드 GIF 거부 (PHP/Zend Framework 사용)

답변

1

gd 라이브러리를 사용하면 이미지를 저장할 수 있습니다. GIF 파일 형식은 애니메이션 인 경우 gif 파일의 첫 번째 프레임 만 저장합니다. 자세한 사용 방법은 imagegif 함수를 참조하십시오.

0

형성 PHP: imagecreatefromgif - Manual :

I wrote two alternate versions of ZeBadger's is_ani() function, for determining if a gif file is animated 

Original: 
http://us.php.net/manual/en/function.imagecreatefromgif.php#59787 

The first alternative version is just as memory intensive as the original, and more CPU intensive, but far simpler: 

<?php 
function is_ani($filename) { 
    return (bool)preg_match('#(\x00\x21\xF9\x04.{4}\x00\x2C.*){2,}#s', file_get_contents($filename)); 
} 
?> 

The second alternative is about as CPU intensive as the original function, but uses less memory (and may also result in less disk activity) 

<?php 
function is_ani($filename) { 
    if(!($fh = @fopen($filename, 'rb'))) 
     return false; 
    $count = 0; 
    //an animated gif contains multiple "frames", with each frame having a 
    //header made up of: 
    // * a static 4-byte sequence (\x00\x21\xF9\x04) 
    // * 4 variable bytes 
    // * a static 2-byte sequence (\x00\x2C) 

    // We read through the file til we reach the end of the file, or we've found 
    // at least 2 frame headers 
    while(!feof($fh) && $count < 2) 
     $chunk = fread($fh, 1024 * 100); //read 100kb at a time 
     $count += preg_match_all('#\x00\x21\xF9\x04.{4}\x00\x2C#s', $chunk, $matches); 

    fclose($fh); 
    return $count > 1; 
} 
?>