擅长:python、mysql、java
<p>在PHP中,使用<a href="http://php.net/manual/en/function.exif-imagetype.php" rel="nofollow noreferrer">exif_imagetype()</a>:</p>
<pre><code>if (exif_imagetype($filename) === false)
{
unlink($filename); // image is corrupted
}
</code></pre>
<p><strong>编辑</strong>:或者您可以尝试使用<a href="http://php.net/manual/en/function.imagecreatefromstring.php" rel="nofollow noreferrer">ImageCreateFromString()</a>完全加载图像:</p>
<pre><code>if (ImageCreateFromString(file_get_contents($filename)) === false)
{
unlink($filename); // image is corrupted
}
</code></pre>
<blockquote>
<p>An image resource will be returned on
success. <strong>FALSE is returned if</strong> the
image type is unsupported, the data is
not in a recognized format, or <strong>the
image is corrupt</strong> and cannot be loaded.</p>
</blockquote>