我想我可能希望用户能够上传静态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. 在画布上的GIF动画与框架控制
- 2. 动画gif调整大小并上传
- 3. 如何使用Tabris框架在SWT小部件中设置动画图像(gif)
- 4. 如何使用CarrierWave在rails中上传动画GIF?
- 5. 用Lithium框架上传文件
- 6. Java:在其他动画gif上叠加/叠加动画gif
- 7. uibutton上的动画gif
- 8. phonegap :: gmap上的动画gif
- 9. 动画上悬停gif
- 10. 用Javascript框架框架动画
- 11. 如何使用zend框架上传AWS s3上的文件2.3
- 12. 在Tomcat服务器上使用Spark框架上传文件
- 13. 启动画面中的GIF文件Ionic
- 14. Android-从文件中播放GIF动画
- 15. (PHP)Imagick创建的gif动画:设置框架处置?
- 16. 在调整大小时存储动画gif的框架
- 17. 在Cocoa中创建一个动画GIF - 定义框架类型
- 18. 如何在Button控件上使用动画GIF?
- 19. Fabric.js画布上的动画GIF
- 20. 移动gif动画文件失去与imagegif动画
- 21. 使用SwiftGif缓动gif动画
- 22. 如何在java中使用动画gif文件作为启动画面?
- 23. 动画gif不是动画
- 24. 播放框架多文件上传
- 25. RestEasy客户端框架文件上传
- 26. 发挥框架文件上传
- 27. Django Rest框架上传的文件Url
- 28. Django其他框架和文件上传
- 29. 与ZK框架上传文件
- 30. zend框架多输入文件上传