Sorry for replying so late! For some reason the automatic notification didn't work and I now found this thread with several replies. Thanks for all the help!
I'm still having troubles making this download to work. Firstly, the videos are in a zip file, but I can ofcourse let people download the .wmv if that makes the script to work. Unfortunately I cannot use non-public directories in the server.
I have been googling and searching the forums and some time ago I came across a pretty nice solution made for PHP5:
//Defining file read function
function readfile_chunked($filename,$retbytes=true) {
$chunksize = 1*(1024*1024); // how many bytes per chunk
$buffer = '';
$cnt =0;
// $handle = fopen($filename, 'rb');
$handle = fopen($filename, 'rb');
if ($handle === false) {
return false;
}
while (!feof($handle)) {
$buffer = fread($handle, $chunksize);
echo $buffer;
ob_flush();
flush();
if ($retbytes) {
$cnt += strlen($buffer);
}
}
$status = fclose($handle);
if ($retbytes && $status) {
return $cnt; // return num. bytes delivered like readfile() does.
}
return $status;
}
//Passing the file
$file= $dl_location . $dl_filename;
$content_len=@filesize($file);
header("Content-length: $content_len");
header("Content-type: application/zip");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
header("Content-Disposition: attachment; filename=$dl_filename");
set_time_limit(0);
readfile_chunked($file);
This finally sends me the file in its total size of either 250MB or around 450MB, but when I try to unzip I get a corrupt archive error (End-of-central-directory signature not found.). I checked the bytes of the file, exactly correct. I also tried with a .wmv, doesn't play either.
I believe I'm very close to the solution, but I just don't know where's the small thing which forbids me from getting it work correctly. I would REALLY appreciate your help!
By the way, I will look at the .htaccess way, thanks. However, as I want to count the remaining downloads and log every download by ip etc, I don't think it's the best option for me. I have already made a nice web-area for the customers to see their remaining downloads and other stuff.
Thanks again!!