PHP Salt


A little dash of PHP... my collection of php functions

Version: 2.33.2
Last Build: December 29, 2023 20:28pm (PST)

Main Menu

Home

Get PHP Salt


The Functions

array
db
file
graph
html
mail
math
misc
mobile
script
string
system
time
web
psSendDownload()
Sends out a file for Downloading


Description:

This quick function sends a file to the browswer for download,
forcing the browser to download it instead of opening/viewing it.



Usage:

psSendDownload($wFile,{$oName})
$wFile is a path to the file you want to send out
$oName is the output file name reported to the brownser



Example:

$wFile = "/media/artwork/logo.jpg";

psSendDownload($wFile);




Code:


function psSendDownload($wFile,$oName="")
{
if ($oName == "") { $oName = basename($wFile); }

set_time_limit(0); // if its a big file
ob_clean(); // clear any pre output
header("Content-type: application/octet-stream");
header("Content-Description: Download file '$oName'");
header("Content-Disposition: attachment; filename=\"$oName\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . filesize($wFile));
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Expires: 0");
header("Pragma: public");
readfile($wFile);
exit();
}

Changlelog:

03/07/2016 - Added option to change the output file name

See Also

And a shot out to:

PHP - php.net
Fedora Server - getfedora.com
Shameless ads to pay for site