Ok, you're going to have to change how the download process works.
Instead of linking directly to the file itself, you need to go through another file, which will then tell the browser to download the file.
So, change your current code to:
PHP Code:
<?php
echo "<a href='download.php?file=http://localhost/images/images.rar&id={$id}'> Please download this movie</a>";
?>
Then make a new file called download.php:
PHP Code:
<?php
if(isset($_GET['file'])) {
$file = $_GET['file'];
$id = mysql_real_escape_string($_GET['id']);
if(file_exists($file)) {
// Set headers
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: application/octet-stream");
header("Content-Transfer-Encoding: binary");
$update = mysql_query("update movie database set download=1 where id='$id'");
} else {
echo 'That file does not exist.';
}
}
?>
That should do it.
You should note that the user may click cancel when presented with the option of downloading the file, so the file download counter may not be 100% accurate.
P.S: Doing it this way will take the user to a blank page, where the file is downloaded. To avoid this happening, you can have the download.php page open in a popup. Let me know if you want to know how to do that.
Bookmarks