Stuph Posted September 3, 2006 Share Posted September 3, 2006 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 Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 3, 2006 Share Posted September 3, 2006 its a link with an images one goes to a .exe and the other uses a zip in the link.this is html Quote Link to comment Share on other sites More sharing options...
Stuph Posted September 3, 2006 Author Share Posted September 3, 2006 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 Quote Link to comment Share on other sites More sharing options...
corbin Posted September 3, 2006 Share Posted September 3, 2006 Uhm I forgot exactly how to do it but it involves headers... Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 3, 2006 Share Posted September 3, 2006 http://www.phpfreaks.com/forums/index.php/topic,95433.0.html Quote Link to comment Share on other sites More sharing options...
Stuph Posted September 3, 2006 Author Share Posted September 3, 2006 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 Quote Link to comment Share on other sites More sharing options...
donturo Posted September 3, 2006 Share Posted September 3, 2006 You can do this in your .htaccess fileYou can use this code:AddType application/octet-stream txtThis will make all links to txt files a direct download link....Good luck! Quote Link to comment Share on other sites More sharing options...
Stuph Posted September 3, 2006 Author Share Posted September 3, 2006 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]xI feel like such a noob :P. Quote Link to comment Share on other sites More sharing options...
radar Posted September 3, 2006 Share Posted September 3, 2006 AddType application/octet-stream txtis going to be your best bet... though in your case it would beAddType 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.. Quote Link to comment Share on other sites More sharing options...
Stuph Posted September 3, 2006 Author Share Posted September 3, 2006 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 Quote Link to comment Share on other sites More sharing options...
radar Posted September 3, 2006 Share Posted September 3, 2006 No it shouldn't matter at all.. Give it a shot if it doesnt work let us know we'll help figure something out. Quote Link to comment Share on other sites More sharing options...
Stuph Posted September 4, 2006 Author Share Posted September 4, 2006 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.htmWhen 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 mp3Much help required :P.Thanks,[b]Ronan[/b]xEdit: The files permissions are '-rwxr-xr-x' if that means anything. Quote Link to comment Share on other sites More sharing options...
mariocesar Posted September 7, 2006 Share Posted September 7, 2006 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 Quote Link to comment Share on other sites More sharing options...
Stuph Posted September 12, 2006 Author Share Posted September 12, 2006 Help? Quote Link to comment Share on other sites More sharing options...
SharkBait Posted September 13, 2006 Share Posted September 13, 2006 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 ;) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.