找到文件:source/module/forum/forum_attachment.php,在230行下面追加下面的代码:

function detect_encoding($file) { // 这个函数用来检测txt文件的编码
    $list = array('gbk', 'utf-8');
    $str = file_get_contents($file);
    foreach ($list as $item) {
        $tmp = mb_convert_encoding($str, $item, $item);
        if (md5($tmp) == md5($str)) {
            return $item;
        }
    }
    return null;
}
// 判断是否是txt内容
if(strpos($attach['filename'], '.txt') !== FALSE) {
 
    $filecontent = file_get_contents($filename);
    $pconfig['msg'] = $filecontent."{$_G['uid']}";
    $fp = fopen($filename,"rb");
    $str ="";
    while(!feof($fp)){
        $str .= fgets($fp);
    }
    $dateline = date('Y-m-d H:i:s');
    $newmsg = "该资源由会员【{$_G['username']}】【ID:{$_G['uid']}】于【{$dateline}】下载自 
    顶尖源码  域名:www.djyuanma.com,仅限本人使用";
    $newfilename = $filename.'_tmp';
    unlink($newfilename);
    $charset = detect_encoding($filename);
    if(!empty($charset)) {
        if($charset == 'gbk' && $_G['charset'] == 'utf-8') {
            file_put_contents($newfilename, $str.PHP_EOL.iconv('UTF-8', 'GBK', $newmsg));
        } elseif($charset == 'utf-8' && $_G['charset'] == 'gbk') {
            file_put_contents($newfilename, $str.PHP_EOL.iconv('GBK', 'UTF-8', $newmsg));
        } else {
            file_put_contents($newfilename, $str.PHP_EOL.$newmsg);
        }
    }
    $filename = $newfilename;
    //$attach['filename'] = $attach['filename'].'_tmp'; // 客户的dz版本必须要这行才能正常添加
    //$filesize = filesize($filename);

原理就是当有人访问下载时,会临时生成一个tmp文件,这个文件里追加下载人的信息,然后下载。

评论 (0)
嘿,我来帮您