Jump to content

Archived

This topic is now archived and is closed to further replies.

Stuph

How do I create "Do you want to run or save this file?" links?

Recommended Posts

Hello everyone,

I was just wondering if someone could please tell me how I can get one of those links on webpages so that when you click on it (in IE) it says "Do you want to run or save this file?"

I'm sure you know what I'm talking about, they normally say stuff like 'Click here to download...' Download.com is full of them.

If anybody knows how to do it in JavaScript or PHP then can you please tell me.

Thanks,
[b]Ronan[/b]x

Share this post


Link to post
Share on other sites
its a link with an images one goes to a .exe and the other uses a zip in the link.

this is html

Share this post


Link to post
Share on other sites
I don't really understand what you're saying.

Basically I want a link on my webpage (either HTML or PHP) that says 'Click here to download the MP3'.

And then when a user clicks the on the link I want it to come up with the "Do you want to run or save this file?" box. Then they can either listen to the MP3 by clicking 'Run' or download it by clicking 'Save'.

I've seen other people do it using some kind of PHP code but I haven't been able to view the source code.

Thanks again,
[b]Ronan[/b]x

Share this post


Link to post
Share on other sites
Ok thanks guys thats all looks very promising, but how do I use it in real life terms?

I mean how, where and why would this work?

Cheers,
[b]Ronan[/b]x

Share this post


Link to post
Share on other sites
You can do this in your .htaccess file

You can use this code:


AddType application/octet-stream txt

This will make all links to txt files a direct download link....

Good luck!

Share this post


Link to post
Share on other sites
Hey thanks,

That code also looks quite helpful but I still don't know how to use it. I kind of understand the whole .htaccess thing but it doesn't seem to work.

I mean I'm not even sure if my web server is Apache PHP or not, and I don't know if that even matters.

Could someone please explain it in layman's terms for me. I'm so confused.

Cheers,
[b]Ronan[/b]x

I feel like such a noob :P.

Share this post


Link to post
Share on other sites
AddType application/octet-stream txt

is going to be your best bet...  though in your case it would be

AddType application/octet-stream mp3

I believe..  in your root folder on your host you should have a .htaccess file.. open this up add that in there and all mp3's should pop up that do you want to run or save dialog that you speak of.  that is unless the person has download accelerator plus -- then it'll just download it regardless..

Share this post


Link to post
Share on other sites
Ok thanks I will try it.

Would it matter if the MP3 file wasn't in the same directory or domain?

Cheers,
[b]Ronan[/b]x

Share this post


Link to post
Share on other sites
No it shouldn't matter at all..  Give it a shot if it doesnt work let us know we'll help figure something out.

Share this post


Link to post
Share on other sites
Well I've tried it, but it doesn't seem to make any difference.

I've put the .htaccess file in the highest directory that I can reach on my server but I don't think it's the top one, it's just the 'www' folder.

Basically I think my server is like this:

ftp://  ->  subdomain.domain.com  ->  home  ->  www  ->  subdomain.domain.com  ->  index.htm

When I log in it goes to the 'www' folder. And I can't go higher.

I don't really know how all this stuff works.

My .htaccess file says this (and only this):

AddType application/octet-stream mp3

Much help required :P.

Thanks,
[b]Ronan[/b]x

Edit: The files permissions are '-rwxr-xr-x' if that means anything.

Share this post


Link to post
Share on other sites
hello, I have a page with little pictures of word documents, and a directory with the word documents (templates), I want our customers to have the choice to download the template when they click the little picture.
Thanks

Share this post


Link to post
Share on other sites
If you want it to give the user the option to save the file or open the file then you need to use headers like this:

[code]
<?php
if(file_exists($the_file)) {
if(filesize($the_file) == $fs) {
$dl++;
$qry = "UPDATE support_files SET downloads = '{$dl}' WHERE file_id = '{$uid}'";
$query = mysql_query($qry) or die ("MySQL Error: <br />{$qry}<br />". mysql_error());
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: {$ft}");
header("Content-disposition: attachment; filename={$fn}");
header("Content-Length: {$fs}");
header("Content-Transfer-Encoding: binary");
readfile($the_file);
exit();
} else {
$message .= "<p>The file size is incorrect. Please notify the
<a href=\"mailto:support@.com\">Support</a> team about this.</p>\n";
}
} else {
$message .= "<p>That file could not be located.  Please notify the
<a href=\"mailto:support@.com\">Support</a> team about this.</p>";
}
?>
[/code]

Also note when using headers your file size has to be correct or it will corrupt the file.  If any text output is echo'd before the file is downloaded the echoing text will be added to the header of the file corrupting it too. This is what I have have found when people were complaining about corrupted downloads ;)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.