1
if ($_SERVER['REQUEST_METHOD']=='GET' && $_GET['download']==='1')
{
    $handle = fopen('lastdownload.txt','rw');
    $date = @fread($handle,filesize('lastdownload.txt'));

    if (time() - 30 * 60 > $date)
    {
    fwrite($handle,time());
    header('Content-type: application/zip');
    header('Content-Disposition: attachment; filename="dwnld_'.date('d_m_Y_H_i',filemtime('download.zip')).'.zip"');
    readfile('download.zip');
    }

    exit;
}

大家好,我有一个关于限制下载次数的问题。

我想限制我的下载次数。

如果有人使用 ?download=1 请求文件

它检查当前时间和文件内的时间

如果在最后一次下载前 30 分钟过去了,它会让你再次下载,否则它就会退出。

请问有什么帮助吗?

谢谢你。

4

3 回答 3

1

除非您仍在使用 PHP4,否则我只会使用file_put_contents()and file_get_contents().

于 2010-02-10T13:06:00.813 回答
0
if(fileatime("lastdownload.txt")>=300)
    {
    //Access OR File Download Code Here
    }
于 2014-01-20T13:30:12.250 回答
0

“rw”不是 fopen 的有效模式。您应该使用 "r+" 或 "x+" 并在阅读后倒回文件指针:

$handle = fopen('lastdownload.txt','r+');
$date = @fread($handle,filesize('lastdownload.txt'));
rewind($handle);
于 2009-09-14T09:28:41.033 回答