Im using the following code to download a big file like 250mb:
if(file_exists($leadon))
{
set_time_limit(0);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.$file_name);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($leadon));
header('Content-Description: File Transfer');
ob_clean();
flush();
readfile($leadon);
exit;
}
die();
But the file is partially downloaded like 18mb to 75mb depending on the speed of the internet. The server administrator told me that Im triggering 500 error code (Internal Error) and the server security considers its under attack and blocks my IP, Please help me on this, what could cause triggering an internal error or security breach?
I copied it into a temp directory and let user download by header(redirect) and removed the files that are older than 24 hours then the page reloads and any other file download is requested. I have given the code below, please let me know if there is any better solution.
if(file_exists($leadon))
{
$temp_folder = time();
$olderTime = $temp_folder-(24*60*60);
$temp_dir = $tempdir.$temp_folder;
create_dir($temp_dir, 0775);
$dirs = glob($tempdir.'*'); // get all file names
foreach($dirs as $dir)
{ // iterate files
if(is_dir($dir))
{
$temp_dir_name = explode('/',$dir);
$dir_name = $temp_dir_name['1'];
if(intval($dir_name) < intval($olderTime))
{
deleteDir($dir);
}
}
}
set_time_limit(0); //Set the execution time to infinite.
$file_name = str_replace(' ', '_', basename($leadon));
//
$temp_file = $temp_dir."/".$file_name;
copy($leadon, $temp_file);
header('Location: '.$doman_name.'/'.$temp_file);
exit();
}