PHP-计数下载 [英] PHP - Count downloads
本文介绍了PHP-计数下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想计算PHP的文件下载量.下载次数应存储在.TXT文件中.
I'ld like to count file downloads with PHP. The downloads number should be stored in a .TXT file.
那怎么办? 谢谢 乌里
How that can be done? Thanks Uli
推荐答案
创建一个名为download.php
的文件,其内容如下:
Create a file named, say, download.php
, with the following content:
<?php
$Down=$_GET['Down'];
?>
<html>
<head>
<meta http-equiv="refresh" content="0;url=<?php echo $Down; ?>">
</head>
<body>
<?php
$filePath = $Down.".txt";
// If file exists, read current count from it, otherwise, initialize it to 0
$count = file_exists($filePath) ? file_get_contents($filePath) : 0;
// Increment the count and overwrite the file, writing the new value
file_put_contents($filePath, ++$count);
// Display current download count
echo "Downloads:" . $count;
?>
</body>
</html>
在另一个页面中放置一个指向它的链接,并将要下载的文件作为参数:
Put a link to it in another page, with the file to be downloaded as a parameter:
download.php?Down=download.zip
答案参考 Dreamincode回答类似的问题
这篇关于PHP-计数下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文