第 1 条附言 · 2015-05-09 13:43:31 +08:00
那么问题来了,我是在找黑吗??怎么防止呢?判断下$_GET['url'];是不是好点
$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;
?>