i'm try to create download link in my form so people can download the files in the upload folder.I'm used code below
<?php
$path = $_SERVER['DOCUMENT_ROOT']."/content/uploads/"; // change the path to fit your websites document structure
$fullPath = $path.basename($_REQUEST['download_file']);
if (is_readable ($fullPath)) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts["extension"]);
switch ($ext) {
case "pdf"||"docx"||"doc"||"jpg"||"jpeg":
header(("Content-type: lappication/pdf")||("Content-type: application/msword")||("Content-type: image/jpeg")); // add here more headers for diff. extensions
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachment' to force a download
break;
default;
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
}
header("Content-length: $fsize");
header("Cache-control: private"); //use this to open files directly
readfile($fullPath);
exit;
} else {
die("Invalid request");
}
and then i test by put download link in my form
<h2>Forms Available</h2>
<a href="content/grants/download.php?download_file=some.pdf">Download here</a>
<a href="content/grants/download.php?download_file=">Download here</a>
<a href="content/grants/download.php?download_file=IntroLetter.docx">Download here</a>
<a href="content/grants/download.php?download_file=Conference Grant Application Form.doc">Download here</a>
from that 4 download link. the first 1 return "invalid request" which i know because that file doesn't exist. second link pop up download box to download empty file. which i bet because it really empty. for third and fourth link that file really exist in the folder but it return
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@miitresearch-postgraduates.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request
what could be the problem? TQ :)