Jump to content

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


Stuph

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

Link to comment
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
Link to comment
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.
Link to comment
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..
Link to comment
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.
Link to comment
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 ;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.