Home html Link to download the .txt and .pdf file

Link to download the .txt and .pdf file

Author

Date

Category

How to make it download and not open in the browser?


Answer 1, authority 100%

roughly speaking like this:

header ('Content-type: application / pdf');
header ("Content-Disposition: attachment; filename = \" 1.pdf \ "");
$ x = fread (fopen ("1.pdf", "rb"), filesize ("1.pdf"));
echo $ x;

There is also such a tip for webservers with .htaccess support, but I have not tried:
htaccess is a simple configuration file that allows you to change the web server configuration on the webmaster side. It is he who helps to bypass those prohibitions that the hoster sets, since the hoster does not provide the configuration file itself for editing, but it makes it possible to manage the web server parameters using .htaccess

In which you want to add a record in the form.

AddType application / download .pdf
or depending on how the file is saved
AddType application / octet-stream .pdf
or
AddType application / force-download .pdf

After that, all pdf files will be downloaded to your computer, and not opened in the browser.

or a strange way:

You can also insert download = “”
into the link.

& lt; a href = "1.pdf" target = "_ blank" download = "" & gt; Download PDF & lt; / a & gt;

Answer 2, authority 10%

Create a download.php file, paste the code below, save it, drop it into the folder where we have the page and write on the page:

& lt; a href = "dowloads.php? file = downloadable file" & gt; Downloadable file & lt; / a & gt ;

Code in dowloads.php:

if (file_exists ($ filename)) {
  header ("Content-type: application / x-download");
  header ("Content-Disposition: attachment; filename = $ filename");
  readfile ($ filename);
} else {header ("HTTP / 1.1 404 Not Found"); echo '404 Not Found'; }
? & gt;

Something like this.


Answer 3

As far as I remember, through HTML – no way. But in general, on the server side, you can change the content-type so that the file is likely to be downloaded …

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions