Hello, I writing a way to allow people to upload pdf files using my script. I want people to download the pdf file instead of opening it in their web browser. I google this and found that you can do it in javascript. Anyone know how to do this in javascript?
Thanks NinjaWork. That was for php code. I am looking javascript version. I might end up using that if I can't find a javascript code.
Hey, thanks SGBoise, I did a little research for you, can you add these headers and see if it works: Content-type: application/octet-stream Content-Disposition: attachment; filename="myfile.pdf" Code (markup):
here you go...a little copy and paste ;-) <?php header("Content-Type:application/octet-stream"); header("Content-Disposition:attachment;"); $fName = basename($_GET['file']); fpassthru($fName); ?> Just save that file where you store the files on the server. If all your movies and that file were in a folder called videos, and you wanted to download "random.wmv", then you'd do this: <a href="videos/filedownload.php?file=random.wmv">Cool Video!</a> Code (markup): from http://www.kirupa.com/forum/showthread.php?t=46853
You can not do this with javascript only, as the headers inside html will be read after the browser has assumed that this is a webpage.. ( and then it is too late to change them to understand it is not a page but a file for download..)
Hi, I need to allow users to download mp3 file when they click on the link. But its opening the video in media player. but i dont want it to happen. It should open a save dialog to save the mp3 file. i need to use only Javascript. Any help. Its very urgent
to do this you just need to make a full href to http://yoursite.com/yourfilepath/yourfile with target='_blank' in your <a href='http://yoursite.com/yourfilepath/yourfile.mp3' target='_blank'>download</a>