PHP Salt


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

Version: 2.20.2
Last Build: October 16, 2017 12:40pm (PST)

Main Menu

Home

Get PHP Salt


The Functions

array
file
graph
html
mail
math
misc
mobile
script
string
system
time
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:

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