Below function is used for download the file. This function will take file name and filepath as an argument.
- function force_download_file($file, $filePath){
- //set the file path
- $dir = $filePath;
- //chek the file is exist or not
- if ((isset($file))&&(file_exists($dir.$file))) {
- //set the content type
- header(“Content-type: application/force-download”);
- header(‘Content-Disposition: inline; filename=”‘ . $dir.$file . ‘”‘);
- header(“Content-Transfer-Encoding: Binary”);
- header(“Content-length: ”.filesize($dir.$file));
- header(‘Content-Type: application/octet-stream’);
- header(‘Content-Disposition: attachment; filename=”‘ . $file . ‘”‘);
- readfile(“$dir$file”);
- } else {
- echo “No file selected”;
- } //end if
- }