If you want certain files to download instead of opening in new tab, you can use the below snippet.
Syntax
1
2
3
|
<php
force_download("image.jpg");
?>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
function force_download($file)
{
$dir = "../log/exports/";
if ((isset($file))&&(file_exists($dir.$file))) {
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";
}
}
|
1
2
3
|
<php
force_download("image.jpg");
?>
|
Hello Friends! I am Ramana a part time blogger from Hyderabad.
0 comments:
Post a Comment