因为有时候拉图片拉的不完整,所以判断下MD5
<?php
$target = $_GET['url'];
$filename = basename($target);
$tupian = './cache/'.$filename;
$kzm = explode(".",$filename);
$tupian_md5 = $tupian.'.txt';
if (file_exists($tupian_md5) ) {
if (count(file($tupian_md5)) == '1')
{
$md5file = md5_file($tupian);
file_put_contents($tupian_md5,PHP_EOL.$md5file,FILE_APPEND);
$content = file_get_contents($tupian);
}
else if (count(file($tupian_md5)) == '2' && substr_count(file_get_contents($tupian_md5),mb_substr(file_get_contents($tupian_md5),0,32)) == 2)
{
$content = file_get_contents($tupian);
}
else if (count(file($tupian_md5)) == '2' && substr_count(file_get_contents($tupian_md5),mb_substr(file_get_contents($tupian_md5),0,32)) != 2)
{
@
unlink($tupian);
@
unlink($tupian_md5);
$content = file_get_contents($target);
}
else
{
$content = file_get_contents($tupian);
}
}
else {
$md5file_t = md5_file($target);
file_put_contents($tupian_md5,$md5file_t);
$content = file_get_contents($target);
$fp = fopen($tupian, 'w+');
fwrite($fp, $content);
fclose($fp);
}
header('Content-Type: image/'.end($kzm).'');
echo $content;
?>
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
https://www.v2ex.com/t/191254
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.