![Andrew Martinez Andrew Martinez](//static.vivaolinux.com.br/imagens/fotos/desconhecido.png)
andrewsec
(usa Ubuntu)
Enviado em 25/08/2014 - 21:54h
Olá pessoal, criei um script em php para forçar o download os arquivos em meu site, mas quando os usuários fazem o download através desse script o site fica indisponível até que o download termine e isso está acabando também sobrecarregando o apache.
Alguém faz ideia do que possa ser?
Segue o código php:
<?php
$arquivo = "file/" . basename($_GET["file"]);
$size = filesize($arquivo);
if(isset($arquivo) && file_exists($arquivo)){
switch(strtolower(substr(strrchr(basename($arquivo),"."),1))){
case "pdf": $tipo="application/pdf"; break;
case "exe": $tipo="application/octet-stream"; break;
case "zip": $tipo="application/zip"; break;
case "doc": $tipo="application/msword"; break;
case "xls": $tipo="application/vnd.ms-excel"; break;
case "ppt": $tipo="application/vnd.ms-powerpoint"; break;
case "gif": $tipo="image/gif"; break;
case "png": $tipo="image/png"; break;
case "jpg": $tipo="image/jpg"; break;
case "mp3": $tipo="audio/mpeg"; break;
case "php": // deixar vazio por seurança
case "htm": // deixar vazio por seurança
case "html": // deixar vazio por seurança
}
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-length: $size");
header('Content-Disposition: attachment; filename="'.$arquivo'"');
header("Content-Type: mime/type");
header("Content-Transfer-Encoding: binary");
readfile($arquivo);
exit;
}else{
echo "<script>window.alert('ERRO!');window.history.go(-1);</script>";
return false;
}
}
?>