User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 360,995 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,424 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting

Save Target as...

Join Date: Oct 2004
Location: San Francisco, CA
Posts: 337
Reputation: paradox814 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
paradox814's Avatar
paradox814 paradox814 is offline Offline
Posting Whiz

Solution Re: Save Target as...

  #24  
Feb 22nd, 2006
$file is the actual file (with the path included)
$new_filename is the filename that you want to send to the user. So when they download this will be the name used by the browser

the first 3 headers force the browser to download the file each and every single time, eg it's not pulling it from the memory/dish cache

the content type is just sent as some binary data type
the content-disposition tell the browser to force a download, do not open in the browser, even if you have a plugin to open it.

i use this script for images, word documents, pdfs and it works just fine.

[php]if (is_file($file))
{
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Pragma: no-cache");

header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=".$new_filename);
readfile($file);
exit();
}[/php]
 
All times are GMT -4. The time now is 6:37 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC