views:

242

answers:

2
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;
}

Hi everyone, i have a problem about limiting download count.

I want to limit my download count.

If someone request the file with ?download=1

It checks the current time and the time inside the file

If 30 minutes passed before the last download, it lets you download again, else it just exits.

Any help please?

Thank you.

A: 

"rw" is not a valid mode for fopen. You should use "r+" or "x+" and rewind the file pointer after reading:

$handle = fopen('lastdownload.txt','r+');
$date = @fread($handle,filesize('lastdownload.txt'));
rewind($handle);
Heri
+1  A: 

Unless your still using PHP4, I would just use file_put_contents() and file_get_contents().

kemp