OZONE Asylum
Forums
Stupid Basic HTML
How do you make a link to cause a download
This page's ID:
28099
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
While the right click to save thing is fine, some times you want certain functionality - and alot of users dont actually use the right click... There is nothing wrong with a download box since it still gives you the option to open or save. I have used this php code for a while and it seems to work fine. [code] $fileName = 'myfile'; $fileExtension = 'pdf'; $sourceFile = $fileName . ' . ' . $fileExtension; $outputFile = $sourceFile; // the name they save as can be different to the existing file // required for IE, otherwise Content-disposition is ignored if(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off'); switch( $fileExtension) { case "pdf": $ctype="application/pdf"; break; case "exe": $ctype="application/octet-stream"; break; case "zip": $ctype="application/zip"; break; case "doc": $ctype="application/msword"; break; case "xls": $ctype="application/vnd.ms-excel"; break; case "ppt": $ctype="application/vnd.ms-powerpoint"; break; case "gif": $ctype="image/gif"; break; case "png": $ctype="image/png"; break; case "jpeg": case "jpg": $ctype="image/jpg"; break; default: $ctype="application/force-download"; } session_cache_limiter(""); header("Pragma: public"); // required header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); // required for certain browsers header("Content-Type: $ctype"); header("Content-Disposition: attachment; filename=".basename($outputFile).";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($sourceFile)); @readfile("$sourceFile") ; // This is the bit that prompts for the download, supress errors for niceness exit(); [/code] [small](Edited by [url=http://www.ozoneasylum.com/user/2564]H][RO[/url] on 06-21-2006 17:55)[/small]
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »