在ecshop文件下载(下载次数、ip、时间)

.php中的代码

<?php define(‘IN_ECS’, true); require(dirname(__FILE__) . ‘/includes/init.php’); if ((DEBUG_MODE & 2) != 2) { $smarty->caching = true; } $times=times($smarty->template_dir); $smarty->assign(‘times’, $times); if (!empty($_REQUEST[‘act’]) && $_REQUEST[‘act’] == ‘price’) { download($smarty->template_dir,’meiyiShop.apk’); // GetIP(); } $smarty->display(‘download.dwt’); function GetIP(){ if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown")) $ip = getenv("HTTP_CLIENT_IP"); else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown")) $ip = getenv("HTTP_X_FORWARDED_FOR"); else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown")) $ip = getenv("REMOTE_ADDR"); else if (isset($_SERVER[‘REMOTE_ADDR’]) && $_SERVER[‘REMOTE_ADDR’] && strcasecmp($_SERVER[‘REMOTE_ADDR’], "unknown")) $ip = $_SERVER[‘REMOTE_ADDR’]; else $ip = "unknown"; return($ip); } function download($address,$name){ header("Content-type:text/html;charset=utf-8"); // $file_name="cookie.jpg"; $file_name=$name; //用以解决中文不能显示出来的问题 $file_name=iconv("utf-8","gb2312",$file_name); $file_sub_path=$address; $file_path=$file_sub_path."/download/".$file_name; //首先要判断给定的文件存在与否 if(!file_exists($file_path)){ echo "没有该文件文件"; return ; } $fp=fopen($file_path,"r"); $file_size=filesize($file_path); //下载文件需要用到的头 Header("Content-type: application/octet-stream"); Header("Accept-Ranges: bytes"); Header("Accept-Length:".$file_size); Header("Content-Disposition: attachment; filename=".$file_name); $buffer=1024; $file_count=0; //向浏览器返回数据 while(!feof($fp) && $file_count<$file_size){ $file_con=fread($fp,$buffer); $file_count+=$buffer; echo $file_con; } fclose($fp); add_ip($address); add_times($address); } function add_times($address){ $file_sub_path=$address; $file_path=$file_sub_path."/download/"."times.txt"; $homepage = file_get_contents($file_path); $data=(int)($homepage); $data++; File_put_contents($file_path,$data); } function times($address){ $file_sub_path=$address; $file_path=$file_sub_path."/download/"."times.txt"; $homepage = file_get_contents($file_path); return $data=(int)($homepage); } function add_ip($address){ $ip= GetIP(); date_default_timezone_set(‘Asia/Shanghai’);//设置时区为中国时间 $time=date("Y/m/d H:i:s"); //用data()取得时间 $data="ip地址:".$ip."——————–下载时间:".$time; $file_sub_path=$address; $file_path=$file_sub_path."/download/"."record.txt"; File_put_contents($file_path,$data."\r\n",FILE_APPEND); } ?>

.dwt 文件

<a href="download.php?act=price" >下载</a> <br> <a>下载{$times}次</a>

和三个文件,一个是下载文件,一个是记录次数的文件,一个是记录IP的文件

坚韧是成功的一大要素,只要在门上敲得够久够大声,终会把人唤醒的。

在ecshop文件下载(下载次数、ip、时间)

相关文章:

你感兴趣的文章:

标签云: