有没有办法让PHP检测到损坏的图像? [英] Is there any way to have PHP detect a corrupted image?

查看:106
本文介绍了有没有办法让PHP检测到损坏的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让PHP确定图像文件是否已损坏且无法正常显示?

Is there any way to have PHP determine whether an image file is corrupted and will not be able to display properly?

我试过检查 fopen 并检查网址是否有效,但是没有用!

I've tried to check with fopen and check whether the URL is valid, but it hasn't worked!

推荐答案

Javascript解决方案(涉及jQuery,虽然这应该可以不用它):

Javascript solution (with involving jQuery, though this should be possible to do without it too):

<script type='text/javascript'>
    $(function(){
        var files = [
            'warning-large.png',
            'warning-large-corrupted.png',
            'http://www.example.com/none.gif',
            'http://sstatic.net/stackoverflow/img/favicon.ico'
        ];
        for ( var n in files ) {
            var img = $('<img/>');
            img.error(function(){
                alert('error:\n' + this.src);
            });
            img.load(function(){
                alert('success:\n' + this.src);
            });
            img.attr('src', files[n]);
        }
    });
</script>

这篇关于有没有办法让PHP检测到损坏的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆