I need to download the specified file by clicking on the link for which I used the script below, but when the file is downloaded, it cannot identify the extension of the downloaded file. So, how to get the MIME type of file to upload? _Please, help...
$filename = $_GET['val'];
$filePath = $_SERVER['DOCUMENT_ROOT'] . "dfms/images/uploads/".$filename;
if(file_exists($filePath)) {
echo $fileName = basename($filePath);
$fileSize = filesize($filePath);
header("Cache-Control: private");
header("Content-Type: application/octet");
header("Content-Length: ".$fileSize);
header("Content-Disposition: attachment; filename=".$fileName);
readfile ($filePath);
exit();
}
else {
die('The provided file path is not valid.');
}
source
share