Good day!
This is how you download a .pdf files using the Php..
1. Create a file that name " getfile.php "
Then Copy and Paste this code:
<?php if (isset($_GET['file'])) {
$file = $_GET['file'];
if (file_exists($file) && is_readable($file) && preg_match('/\.pdf$/',$file)) {
header('Content-Type: application/pdf');
header("Content-Disposition: attachment; filename=\"$file\"");
readfile($file);
}
} else {
header("HTTP/1.0 404 Not Found");
echo "<h1>Error 404: File Not Found: <br /><em>$file</em></h1>";
}
?>
2. Create a file name " link.php "..
Then Copy and Paste:
<a href="download.php?file=manual1.pdf" class="main">Users Guide</a>
That's it.They code also can download anything as soon as your files is accurate name and their extension to be able to find out. Hope it helps!
Thanks for reading :D
Status: Done!
No comments:
Post a Comment