We use this script to download a file from a given define file path location
In this script we are using two variable:
1:) $fileName // for file name with path.
2:)$title //for file name changed in you given title name.
<?php
$fileName = "images/image.jpg"; // define static file name with location;
$title = "image-new";
header("Pragma: public");
header('Content-disposition: attachment; filename='.$title);
header("Content-type: ".mime_content_type($fileName));
header("Content-Length: " . filesize($fileName) ."; ");
header('Content-Transfer-Encoding: binary');
ob_clean();
flush();
$chunksize = 1 * (1024 * 1024); // how many bytes per chunk
if (filesize($fileName) > $chunksize) {
$handle = fopen($fileName, 'rb');
$buffer = '';
while (!feof($handle)) {
$buffer = fread($handle, $chunksize);
echo $buffer;
ob_flush();
flush();
}
fclose($handle);
} else {
readfile($fileName);
}
?>
0 Comment(s)