Skip to content

Instantly share code, notes, and snippets.

@danilobatistaqueiroz
Last active August 1, 2018 02:23
Show Gist options
  • Save danilobatistaqueiroz/9c532e3d91826887f8609b8266385136 to your computer and use it in GitHub Desktop.
Save danilobatistaqueiroz/9c532e3d91826887f8609b8266385136 to your computer and use it in GitHub Desktop.
using PHP. List files in a private directory
<?php
// abre o arquivo em modo binário
$fullname = './private/'.$_GET['file'];
$fp = fopen($name, 'rb');
$filename = basename($fullname);
// envia os headers
header("Content-Type: application/zip");
header("Content-Length: ".filesize($fullname));
header('Content-Disposition: inline; filename="'.($filename).'"');
fpassthru($fp);
exit;
<?php
$files = array_diff(scandir('./private'), array('.', '..'));
?>
<html>
<body>
<div>
<button id="update"> download </button>
<?php
foreach($files as $file){
?>
<a href="http://localhost:8080/downloads.php?file=<?= $file ?>"><?= $file ?></a>
<?php
}
?>
</div>
<script src="public/main.js"></script>
</body>
</html>
<?php
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment