Last active
August 23, 2020 03:09
-
-
Save alejandroivan/b583b2a7cbae13281af72f44dca490af to your computer and use it in GitHub Desktop.
PHP output contents of file
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 | |
$file_path = "/full/path/of/the/file.doc"; | |
if ( file_exists($file_path) ) { | |
$file_name = basename($file_path); | |
$mime_type = mime_content_type($file_path); | |
$file_size = filesize($file_path); | |
header('Content-Description: File Transfer'); | |
header("Content-Type: {$mime_type}"); | |
header("Content-Disposition: attachment; filename=\"{$file_name}\""); | |
header("Expires: 0"); | |
header("Cache-Control: must-revalidate"); | |
header("Pragma: public"); | |
header("Content-Length: {$file_size}"); | |
readfile($file_name); // Esto imprime el contenido del archivo | |
} | |
else { | |
http_response_code(404); | |
echo 'File does not exist.'; | |
} | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment