View Full Version : How to make a download link
Wizard13335
09-15-2005, 02:44 AM
Hi everyone. I know how to make a normal download, where the user would right click on a link and select 'save target as', but how do you create those links where the user would just click and the dialog box would appear saying 'would you like to open or save this file?'.
Any help would be appreciated.
cr3ative
09-15-2005, 08:19 AM
Make the server present it as application/ocetet-stream , and I think that the browser will then always prompt.
cr3
Except IE, which thinks it knows better than the server and tries to guess by the file content.
Wizard13335
09-15-2005, 11:13 PM
thx!-
Hybrid
10-08-2005, 09:03 PM
also winzip the folder and link it when clicked it will prompeted to download
yettti
10-12-2005, 04:40 PM
what you can do is creat a link to a zipped folder of wich containest the file or even not a zipped file in some cases
Druza
10-16-2005, 03:13 PM
wait im confused
do what to the sever for the whoosywhatsit now?
Make the server send the Content-Type header as application/octet-stream for that file. This can be done by altering the webserver's configuration.
Druza
10-16-2005, 04:05 PM
um...okay....
hello66
06-15-2006, 07:00 PM
I have no idea what the hell your talking about. Can u be a bit more specific for us that are not technies?? Would like to be able to create a downloadable link also, you know the one where u click it & the dialog box appears. Cannot seem to understand what u mean in your replies. Much appreciated. Ta
atanas1234
06-28-2006, 09:17 AM
Unfotunatly i do not understand anything.I am new in HTML writing so is it possible to be explaind in a low level.Thanks
jad9321
06-30-2006, 02:58 AM
Ok,
Let me try to break this down :) ... A little easier :p .... actually the way I do it.
Say the name of the file is "Hello.zip" I would upload it to my web server to a directory...
Lets say the location of the file is "http://example.com/Hello.zip" I would make a simple link to that location. The code would turn out to be....
<A href="http://example.com/Hello.zip">Click here to download!</A>
Ok? So you guys get it??? :)
There are other ways to do it..... Just to lazy to type them... :]
Hope I Helped,
Joe
djr33
06-30-2006, 03:22 AM
The original question was to set a download to be forced to DOWNLOAD, not just open.
If you just use <a href=...> it will just let you click it and open it... the point is that this will force it to be saved, rather than opened.
As for just linking to something... yes, that would do it.
simonf
06-30-2006, 08:23 AM
Hi
Found this:
<?php
$filename = $_GET['file'];
// required for IE, otherwise Content-disposition is ignored
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');
// addition by Jorg Weske
$file_extension = strtolower(substr(strrchr($filename,"."),1));
if( $filename == "" )
{
echo "<html><title>eLouai's Download Script</title><body>ERROR: download file NOT SPECIFIED. USE force-download.php?file=filepath</body></html>";
exit;
} elseif ( ! file_exists( $filename ) )
{
echo "<html><title>eLouai's Download Script</title><body>ERROR: File not found. USE force-download.php?file=filepath</body></html>";
exit;
};
switch( $file_extension )
{
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";
}
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");
// change, added quotes to allow spaces in filenames, by Rajkumar Singh
header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));
readfile("$filename");
exit();
?>
djr33
06-30-2006, 09:30 AM
Looks like that will only do a force download for those formats that do not fall within any of the first 10 or so filetypes, like jpg, etc.
That's the most pointless script I've ever seen :p
mime_content_type (http://www.php.net/mime-content-type)()
Neko Bat
01-04-2009, 08:33 AM
Go to http://www.goldcoastwebdesigns.com/create-download-link.shtml it is explained there.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.