<?php

/**
 * 图片伪本地化
 * TBlog TBlog博客系统　BY Tmac PHP MVC framework
 * $Author: zhangwentao $  <zwttmac@qq.com>
 * $Id: pic.php 53 2011-12-05 11:10:53Z zhangwentao $
 * http://www.t-mac.org； 
 */
error_reporting(0);
Header("Content-type: image/jpeg");
$m = trim($_GET['m']);
$p = trim($_GET['p']);
if ($m == 'zn') {
    $url = 'http://www.zhuna.cn/' . $p;
} else {
    $url = 'http://p.zhuna.cn/' . $p;
}
$content = GetHttps($url);
echo $content;

function GetHttps($url, $charset = "utf-8")
{
    if (extension_loaded('curl')) {
        $file_contents = curl_file_get_contents($url);
    } else {
        $file_contents = @file_get_contents($url);
    }
    if ($charset == "utf-8") {
        return $file_contents;
    } elseif ($charset == "gb2312") {
        $file_contents = iconv("gb2312", "UTF-8", $file_contents);
        return $file_contents;
    }
}

function curl_file_get_contents($url, $timeout=5)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);    
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $r = curl_exec($ch);
    curl_close($ch);
    return $r;
}

?>