我想我可能希望用戶能夠上傳靜態GIF但不是動畫的。對於虛擬形象來說,因爲他們可能看起來......不專業和分心。有沒有在PHP或Zend框架的方式,我可以驗證文件上傳的方式?文件上傳Deny動畫GIF(使用PHP/Zend框架)
3
A
回答
1
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;
}
?>
相關問題
- 1. 如何使用Tabris框架在SWT小部件中設置動畫圖像(gif)
- 2. 用Lithium框架上傳文件
- 3. 動畫上懸停gif
- 4. phonegap :: gmap上的動畫gif
- 5. 用Javascript框架框架動畫
- 6. 如何使用zend框架上傳AWS s3上的文件2.3
- 7. 在Tomcat服務器上使用Spark框架上傳文件
- 8. Android-從文件中播放GIF動畫
- 9. 啓動畫面中的GIF文件Ionic
- 10. 如何使用Play框架上傳文本文件?
- 11. Fabric.js畫布上的動畫GIF
- 12. 在調整大小時存儲動畫gif的框架
- 13. 移動gif動畫文件失去與imagegif動畫
- 14. 動畫gif不是動畫
- 15. 如何在java中使用動畫gif文件作爲啓動畫面?
- 16. 使用SwiftGif緩動gif動畫
- 17. 動畫GIF在iPhone上不起作用
- 18. XNA gif動畫
- 19. Android:動畫gif
- 20. DirectFB&GIF動畫
- 21. 動畫 - GIF
- 22. jQuery GIF動畫
- 23. Android動畫GIF
- 24. 文件中播放框架上傳
- 25. zend框架多輸入文件上傳
- 26. 發揮框架文件上傳
- 27. 使用JavaScript製作一堆png文件的gif動畫效果?
- 28. 用phpthumb調整動畫GIF動畫
- 29. 用python去動畫動畫gif
- 30. 使用框架動畫精靈cocos2dx 3.2