Brenda813
Brenda813

Reputation: 41

How to Setup A File Download

I need to create a download link, but I'm a little confused as how to do this and my research online is making me more confused.

I setup the following:

<a href="/downloads/filename.pdf" download="filename.pdf">Download Resume</a>

Do I have this right? Is there anything else I need to do?

I was also reading that to force a file to download to the users computer, instead of opening in the browser, you need to add some lines of code to your htaccess file or content type to your header?

I don't know what an htaccess file is and as far as adding content types to the header, do I just need to add some lines to the header or is there another piece to that?

Upvotes: 2

Views: 1326

Answers (5)

Jeff jarrett
Jeff jarrett

Reputation: 11

a href="file path" download>

Eg:

a href="/images/myw3schoolsimage.jpg" download="w3logo"

whereas w3logo would be the file name it will be downloaded, which is optional.

Ref:http://www.w3schools.com/tags/att_a_download.asp

Upvotes: 1

Anoxy
Anoxy

Reputation: 953

<a href="your/path/to/file.pdf" id="link">Download</a>
<style>
#link{ style here}
</style>

You do in no way need to make a form to download a pdf.

Upvotes: 0

hemnath mouli
hemnath mouli

Reputation: 2755

<form method="get" action="/downloads/filename.pdf">
<button type="submit">Download!</button>
</form>

You must first search for the answers and then ask a question. Its been already answered here. How to trigger a file download when clicking an html button or javascript

Upvotes: 0

Dhaval Gadher
Dhaval Gadher

Reputation: 72

For the button you can do

<form method="get" action="file.doc">
<button type="submit">Download!</button>
</form>

Also you can use...

<a href="/documents/large_document.pdf">Download the large document</a>

Upvotes: 0

Carl K
Carl K

Reputation: 984

I believe you are mixing a couple different things together.

The way you have it will download from /downloads/filename.pdf and save the file as filename.pdf via a download prompt. Keep in mind, IE does not support this feature. (http://www.w3schools.com/tags/att_a_download.asp)

You could also use headers to specify content-type and force the browser to download it as an attachment if you were running server side scripts. From the question you asked, this does not seem to be the case. (http://php.net/manual/en/function.http-send-content-disposition.php)

An htaccess file is used by an Apache server to determine specifics about how to serve a file. For example, you could use an htaccess file to specific special URLs, or to prevent users from getting into private folders, etc.

Upvotes: 0

Related Questions