Created
July 10, 2019 08:52
-
-
Save memandip/f600ed4c81604222e276d0096206700f to your computer and use it in GitHub Desktop.
PHP file download
This file contains hidden or 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 | |
$filename = 'filepath.html'; | |
$path = __DIR__ . '/web/uploads/'; | |
$download_file = $path . $filename; | |
if (file_exists($download_file)) { | |
$extension = explode('.', $filename); | |
$extension = $extension[count($extension) - 1]; | |
header('Content-Transfer-Encoding: binary'); | |
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($path)) . ' GMT'); | |
header('Accept-Ranges: bytes'); | |
header('Content-Length: ' . filesize($download_file)); | |
header('Content-Encoding: none'); | |
header('Content-Type: application/' . $extension); | |
header('Content-Disposition: attachment; filename=' . $filename); | |
readfile($download_file); | |
exit; | |
} else { | |
echo 'File does not exists on given path'; | |
} | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment