index.php
- Código: Selecionar tudo
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title>Exemplo de Forçar Download</title>
</head>
<body>
<ul>
<?php
foreach(glob("uploads/*.*") as $v){
$name = basename($v);
echo '<li><a href="baixar.php?file='.$name.'">'.$name.'</a></li>';
}
?>
</ul>
</body>
</html>
baixar.php
- Código: Selecionar tudo
<?php
$pasta = 'uploads';
if(isset($_GET['file']) && file_exists("{$pasta}/".$_GET['file'])){
$file = $_GET['file'];
$type = filetype("{$pasta}/{$file}");
$size = filesize("{$pasta}/{$file}");
header("Content-Description: File Transfer");
header("Content-Type:{$type}");
header("Content-Length:{$size}");
header("Content-Disposition: attachment; filename=$file");
readfile("{$pasta}/{$file}");
exit;
}
?>
