开发者

Downloading files in a webpage

开发者 https://www.devze.com 2023-04-08 06:03 出处:网络
I need to make the user able to download a file from my webpage on clicking a link on my website I tried<a href=\'./image.ext\'>Download file</a>

I need to make the user able to download a file from my webpage on clicking a link on my website I tried <a href='./image.ext'>Download file</a> By it just opened a new window and i need to right click and select "save page as" What I am expected is ,after clicking my link user must see a dialogue box "save as" as usual...How to do it..Is there any way in HTML to force download by showing such a dialogue

Note:Since stackoverflow is not allowing anchor tag,i just typed it as a.Plea开发者_如何学运维se do not treat it as a mistake


If you're using an Apache web server, you can use the .htaccess file to force file download for certain file extensions. Add this line to your .htaccess to cause the "Save As" dialog to appear when the link is clicked:

AddType application/octet-stream .ext

If you wanted the same behaviour for a PDF or AVI, the following lines would do it:

AddType application/octet-stream .pdf
AddType application/octet-stream .avi


You can use php to readfile() the file to the user.

this tutorial would be helpful for you : http://webdesign.about.com/od/php/ht/force_download.htm


I know it is lame, but I found a solution here

0

精彩评论

暂无评论...
验证码 换一张
取 消