bthaxor 0 Report post Posted January 28, 2008 hey all,on my website, i would to link to files that i have created/found. since these files are larger than 5mb, and i didn't want to waste my precious 500mb space, i hosted them on fileden, an online file storage site allowing hotlinking. an example of a url from this site is:http://www.fileden.com/files/2007/10/20/15some%20file.mp3so anyway, on one of my pages i would like to have a link to one of these files. however, instead of streaming the file as the website would normally do for the mp3 extension, i would like to 'force' the save link as / save as dialog to appear.i have thoroughly researched this, however all of the working solutions require the php file to be placed in the same directory as the other files, and with the random urls that fileden generates that is not possible. otherwise, they use the $filename attriibute, which uses relative urls (e.g. ../../some file.mp3), which is also not possible in this case.the javascript solution, which works, is not firefox compatible, and since i always use firefox and am a large fan of it, i find that frustrating.for webdesign i use xhtml+css, and do not know php. which is why i need help, since most/all of the working solutions seemed to use php.so, my question/request: any code which is incorporateable into a html page and takes into consideration my lack of php knowledge, which forces a 'save link as/save as' dialog to appear once the user clicks on a link, and is cross-browser.thanks so much if you are able to help.also, one last thing: if possible, i would like this code to be php/javascript, because they are the easiest to incorporate into html. NO ASP PLEASE!!! Notice from rvalkass: Merged double post. Share this post Link to post Share on other sites
imbibe 0 Report post Posted January 28, 2008 could u post the javascript solution. someone might be able to port it to FF.And according to Xisto rules do not make double posts. edit your original one. Share this post Link to post Share on other sites
bthaxor 0 Report post Posted January 29, 2008 the javascript code (only for ie) is: <a href="java script:void(0);" onclick="document.execCommand('SaveAs',true,'http://fileden.com/somefolder/some file.mp3');">download</a> and sorry about the double post, it is merged. Share this post Link to post Share on other sites
galexcd 0 Report post Posted February 1, 2008 I think the best solution is to zip it. That way all browsers will be forced to download it, but why are you forcing people to download this song? I like to listen to mp3's streaming in my browser. Share this post Link to post Share on other sites
bthaxor 0 Report post Posted February 2, 2008 i would like to force the download because that is exactly what the link is supposed to be: a download. i have asked people if they stream their music, believe me, and NO-ONE did.also, i really wouldn't like to resort to a zip file! that's taking the easy way out... besides, i have already uploaded all my files as mp3's, you have no idea how long that took.one last thing: i can't tell them to right click -> save link as even if i wanted to, because i have a script which disables the right click and is cross browser (at least it stops n00bs from viewing my source... all those who don't know how to user the menu bar).the best approach to this would most likely be a download.php, however as mentioned before i do not know php, and the scripts that are available on the net have so far all required that the php file be placed in the same directory as the files, which is not possible in this case.i have also heard something about content disposition headers... how do they work? Share this post Link to post Share on other sites
iGuest 3 Report post Posted October 27, 2008 (edited) Why not simply use PHP Download Script Replying to bthaxor Just make the link to the mp3 file and use a force download php script <?// Tells the browser that where going to run a PHP script.$file = $_GET['file'];// Get a filename from the GET parameters.Header ("Content-type: octet/stream");Header ("Content-disposition: attachment; filename=".$file.";");Header("Content-Length: ".Filesize($file));// Sends the brower headers to tell it that its sending that file back to it.Readfile($file);// Reads the file from the server and send it to the browser.Exit;?>// Closes the PHP script.Call it forcedownload.PhpThen your link would be <a href="sitelocation/mp3s/forcedownload.Php?file=download.Mp3 Name</a> Place the file forcedownload.Php in the directory with the mp3's You can use this for any file extension. -reply by DiSaSteR MaSteR Edited March 29, 2012 by moderator (see edit history) Share this post Link to post Share on other sites
andresf91 0 Report post Posted January 14, 2009 I would suggest you to allow your visitors to right click, it's so frustrating when you can't click as you wish, and when web developers interfere into my GUI. I just leave the site! Also, newbies are no harm if they sneak into your source code. The problems don't come from them. The problems come from those who already know how to use the menu bar, or better, how to disallow all Javascript. So, if someone wants to find security leaks or steal your "precious HTML coding", use other ways. Anyway, back to the topic, the best solution if you still refuse to allow your visitors to use their left button, use PHP, which doesn't require the file to be in the same directory as the mp3 file to download. The code written by iGuest will work. Copy it from the opening <? to the ending ?>. (But please delete the script that disallow the left click!) Share this post Link to post Share on other sites
rpgsearcherz 5 Report post Posted January 15, 2009 I agree with andres. Allow them to right click on the links, and then they can choose to "Save As" or they can click it normally and stream it if they wish. This helps both groups of people(those who wish to stream and those who don't) and allows them more freedom.To do that, it would be best to just add the text "Right click > Save As..." after it, plain text. This will help them out a little, for those who haven't ever had to use that method before. Share this post Link to post Share on other sites
SofiaComp 0 Report post Posted February 15, 2009 (edited) Just make the link to the mp3 file and use a force download php script <?// Tells the browser that where going to run a PHP script.$file = $_GET['file'];// Get a filename from the GET parameters.Header ("Content-type: octet/stream");Header ("Content-disposition: attachment; filename=".$file.";");Header("Content-Length: ".Filesize($file));// Sends the brower headers to tell it that its sending that file back to it.Readfile($file);// Reads the file from the server and send it to the browser.Exit;?>// Closes the PHP script.Call it forcedownload.PhpThen your link would be<a href="http://forums.xisto.com/no_longer_exists/ Name</a> Place the file forcedownload.Php in the directory with the mp3'sYou can use this for any file extension. Yes, that's the thing try using php's integrated function header(); check that function in php.net, check the mime types that you need, integrate it in your webpage. Edited March 29, 2012 by moderator (see edit history) Share this post Link to post Share on other sites
iGuest 3 Report post Posted August 3, 2009 How to pass a value to an exe on downloadDownload ScriptHi, I want to know how to pass say example UID to an exe / App as param while downloading from php header Will really appreciate the Response. -reply by rasheed Share this post Link to post Share on other sites
iGuest 3 Report post Posted August 21, 2009 PHP download solution not viable for large files...Download ScriptFolks, We're trying to use similar PHP download scripts to offer single click downloads of MP4 files... Problem is, these files are all 500Mb - 1.6Gb. In size. The PHP solutions I've been trying force a file read, and when dealing with files this large, it causes problems. User clicks the link and it's 2 minutes or so (an eternity on the net as you know) for the save-as dialog box to show up. Anybody got any resolution to that end of this problem? Thanks to all who reply. -reply by Tony Jackson Share this post Link to post Share on other sites