我想我可能希望用户能够上传静态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