View Full Version : Force Download?
08-16-2006, 04:44 PM
Hey guys. I need help. A client wants vCards or their employees that people can click and have outlook open. Unfortunately, when I click the current vCard link, it just opens as text in the browser. Is there any way I can force a download so they can choose "open with"? Thanks =)
//Edit: in case you need to see what's going on, www.kaplanbond.com/atts.html
click an attorney and try to open one of their vCards.
Please search the forum before posting.
08-17-2006, 06:18 AM
I think you just missed an opportunity to be both more informative and less polite at the same time. It's really a cr_p shoot, depending upon the browser and a user's configuration. A situation analogous to speed dating and expecting to control your new partner's behavior. If you are really good, you might be able to part of the time. Oh, and do search previous posts. If you know the user's browser and settings and can count on this information it may be doable.
08-21-2006, 01:54 PM
I think you just missed an opportunity to be both more informative and less polite at the same time.
What? Are you saying that I should be less polite and more informative?
Anyways, sorry I didn't do a search first. My fault. But I DID find this PHP script, but I can't quite get it to run properly.
$filename = $_GET['file'];
// required for IE, otherwise Content-disposition is ignored
$file_extension = strtolower(substr(strrchr($filename,"."),1));
if( $filename == "" )
echo "<html><title>Error</title><body>ERROR: download file NOT SPECIFIED. USE force-download.php?file=filepath</body></html>";
} elseif ( ! file_exists( $filename ) )
echo "<html><title>Error</title><body>ERROR: File not found. USE force-download.php?file=filepath</body></html>";
switch( $file_extension )
case "pdf": $ctype="application/pdf"; break;
case "vcf": $ctype="application/vcard"; 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 "jpg": $ctype="image/jpg"; break;
header("Pragma: public"); // required
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
// change, added quotes to allow spaces in filenames, by Rajkumar Singh
header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );
First of all, I'm not sure how to format the filepath. but even without the path, it should tell me file not found, correct? when I go to http://www.kaplanbond.com/test.html and click the link that links to http://www.kaplanbond.com/test1.php?David%20B%20%20Kaplan.vcf it tells me the file was not specified.
If you need more specifics just ask and I'd be happy to reply with what you need. Thanks in advance.
What? Are you saying that I should be less polite and more informative?He meant me :)
Whatever you do, don't use that script. It is shockingly insecure, and will allow anyone access to read any file the user your scripts run as can read! For example, your server's /etc/passwd (http://www.kaplanbond.com/test1.php?file=/etc/passwd). Luckily your host is smart enough to use shadowing, but that's still a serious problem.
08-22-2006, 05:27 AM
what about forcing the file to be a certain name? Instead of reading it from the link.
That's a much better idea. Still, there are easier ways to obtain the effect you desire, such as mwinter's .htaccess idea.
08-23-2006, 03:24 AM
And this is what Twey is refering to I think.
AddType application/octet-stream zip
That would force any and all .zip files to be downloaded without use of the right click save as feature, make sure you don't add a period before the file extension.
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.