我是php的新手我创建了一个文件共享网站,人们上传他们的文件并获得一个链接与其他人分享现在免费注册我想显示文件下载的次数是我的下载。 PHP代码。
<?php
/**
*
* @package Filehost
* @author Ronald Ralinala
* @copyright 2015
* @link http://filehost
* @version 1.0.0
*/
include("./utils/config.php");
include("./utils/functions.php");
include("./utils/classes/filesize.php");
require '/utils/config.php';
$access_id = $_GET["id"];
$page_name = "file download";
$css_type = "download";
include("./utils/templates/header.php");
?>
<div id="content">
<?php
if(!mysql_num_rows(mysql_query("SELECT * FROM `" . $table_prefix . "files` WHERE access_id = '" . mysql_real_escape_string($access_id) . "'"))) {
?>
<img src="/images/instructions.gif" id="instructions" alt="Step 1: Upload your file. Step 2: Share your private link."/>
<div id="box">
<div class="notice">
<h2>File not found</h2>
Please verify the URL.
</div>
</div>
<?php
}else{
// fetch file information
$fileinfo_result = mysql_query("SELECT * FROM `" . $table_prefix . "files` WHERE access_id = '" . mysql_real_escape_string($access_id) . "'");
$fileinfo = mysql_fetch_array($fileinfo_result);
// do expiry calculations
$current_timestamp = time();
$expiry_timestamp = $fileinfo["expiry"];
if( (intval($expiry_timestamp) !== 0) && ($current_timestamp > $expiry_timestamp) ) {
?>
<img src="/images/instructions.gif" id="instructions" alt="Step 1: Upload your file. Step 2: Share your private link."/>
<div id="box">
<div class="notice">
<h2>File has expired</h2>
The file you are trying to download has expired and is no longer available.
</div>
</div>
<?php
}else if( $fileinfo['deleted'] == 1 ) {
?>
<div id="content">
<img src="/images/instructions.gif" id="instructions" alt="Step 1: Upload your file. Step 2: Share your private link."/>
<div id="box">
<div class="notice">
<h2>File Deleted</h2>
The file you are trying to download has been deleted and is no longer available.
</div>
</div>
</div>
<?php
}else{
// Generate a random security string
$security_id = sha1(time() . uniqid());
$client_ip = getClientIP();
$security_expire = time() + (get_config('download_sessionexpiry') * 60);
// Create download session
mysql_query("INSERT INTO `" . $table_prefix . "dlsession` (`id`, `session_id`, `access_id`, `ip_address`, `expiry`) VALUES (NULL, '" . $security_id . "', '" . $access_id . "', '" . $client_ip . "', " . $security_expire . ");");
// set file information
$file_name = $fileinfo["file_name"];
$file_size = $fileinfo["file_size"];
// calculate file size
$file_size_class = new getFileSize();
$size_text = $file_size_class->fileSizeConversion($file_size, 'B');
// create file download url
$file_download_url = "/file/" . $access_id . "/" . $security_id . "/" . rawurlencode($file_name);
?>
<div id="info">
<script type="text/javascript">
document.write("Your download will begin immediately");
setTimeout("window.location = '<?php print $file_download_url; ?>'", <?php print(get_config('download_waittime') * 1000); ?>);
</script>
<noscript>
<a href="<?php print $file_download_url; ?>">Click here to start your download</a>
</noscript>
</div>
<div id="file_info"><strong>
File Name: <i><?php print shorten_title($file_name); ?></i><br />
File Size: <?php print $size_text; ?><br /> <br />
<h1><?php echo file_get_contents('./uploads/counter.txt'); ?> </h1> Page Hits
<?php echo counter.php;?>
</div>
<div id="sponsor">
<div class="message">Thank you!</div>
<div style="height: 250px;">
<?php
// Print out download sponsor code
print(stripslashes(get_config('download_sponsorcode')));
?>
</div>
<img src="/images/ad_box_top_left.gif" style="position:absolute; left:0px; top:0px;" />
<img src="/images/ad_box_top_right.gif" style="position:absolute; right:0px; top:0px;" />
<img src="/images/ad_box_bottom_left.gif" style="position:absolute; left:0px; bottom:0px;" />
<img src="/images/ad_box_bottom_right.gif" style="position:absolute; right:0px; bottom:0px;" />
</div>
<?php
}
}
?>
</div>
<?php
include("./utils/templates/footer.php");
?>
我需要一个下载计数器,有人可以为我添加吗?
答案 0 :(得分:0)
您需要在文本文件中跟踪下载的事件;没有必要的任何数据库存储。
$hit_count = @file_get_contents('hitcount.txt');
// read the hit count from file, save this file on the
// server to get and update hit count
echo $hit_count;
// display the hit count
// from here. just grab contents from the hitcount.txt
//when someone downloads the file
//you want to update the download count
$hit_count++; // increment the hit count by 1
//after the file download successfully, you want to
//run this code to update the count
@file_put_contents('count.txt', $hit_count); // store the new hit count
答案 1 :(得分:0)
首先从数据库中获取所有访问ID的列表
$ access =从表中选择access_id,其中file_id = $ file
然后选择访问ID的下载会话
Foreach访问 计算下载会话
你会得到答案