How in HTML to make a button to download a file instead of opening in the browser

Опубликовано: 12 Октябрь 2019
на канале: Exploring the IT World / Oleg Shpagin / WISEPLAT
27,009
770

Some browsers, by default and after "customizing", open files of certain formats inside themselves for viewing. Most often this .pdf, .txt and images, and naturally media files.

If you need a link to download, and not to open the file, you need to do the following:

In HTML5 it is to tag A simply add the download attribute, without any values, for the earlier version-the same download attribute only assign a value, for example - the name of the file under which the file will be downloaded.

Here is an example of a link to download a file:
[a href= " mb_installation_guide-eu.pdf "download=" instruction to MP.pdf"] download the user manual [/a]

Here is an example of a link in the form of a button to download a file:
[a href= " mb_installation_guide-eu.pdf "title=" Download the user manual "download=" manual for MP.pdf"] [button]instructions for MP [/button] [/a]

Here is an example of a link in the form of a picture button to download a file:
[a href= " mb_installation_guide-eu.pdf "title=" Download the user manual "download=" manual for MP.pdf"][img src=" download-155425__480.png "alt=" instruction to MP " /] [/a]

Please note-that the download of the file, if you run your html document on a local machine, will not occur, because the browser and so sees that this file lies with you.

If you put this file on the hosting, then this attribute will work and the browser will offer to download, if there is no tick-that open all PDF documents in the browser.

For compulsory download file, regardless of settings browser-you must in the root of the site laid out on hosting add the next the Premier in file .htaccess:

ForceType application/octet-stream
[IfModule mod_charset.c]
CharsetRecodeMultipartForms off
[FilesMatch "\.(gif|jpe?g|png)$"]
ForceType none
[/FilesMatch]
Options None
Options-ExecCGI
php_flag_engine off
[/IfModule]

Or so, just for PDF (on hosting add the following lines to the file .htaccess):

[filesmatch "\.(?i: pdf)$"=""]
ForceType application/octet-stream
Header set Content-Disposition attachment

** Note: Angle brackets cannot be placed in the description - so square brackets are used instead [ ] !!! **

html #file # download #file #Trekhgorka #Odintsovo #design #design

Subscribe to our YouTube channel:    / @wiseplat  

Join our VC group: https://vk.com/wiseplat

Ask questions – I will try to answer
Good luck in such cool endeavors!


Смотрите видео How in HTML to make a button to download a file instead of opening in the browser онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Exploring the IT World / Oleg Shpagin / WISEPLAT 12 Октябрь 2019, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 27,009 раз и оно понравилось 770 людям.