Last active
August 1, 2018 02:23
-
-
Save danilobatistaqueiroz/9c532e3d91826887f8609b8266385136 to your computer and use it in GitHub Desktop.
using PHP. List files in a private directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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