I'm trying to implement a click and download functionality in html. The answer I found is
<a href="http://example.com/files/myfile.pdf" target="_blank">Download</a>
But my question is how do I even put "myfile.pdf" in the example.com's url? I tried to put a file in the project's directory, but it can't be accessed with href. I've been searching but can't find any answer.
CodePudding user response:
The file needs to be available on the webserver and if it's a public file this file needs to have Read rights set to Public. Be careful with this and not set write rights to public. How you get your file there is very dependant on your hosting provider.
CodePudding user response:
You can use below template which can generate link of file which can be downloadable.
<a href="/images/ImageName.jpg" download>
<img src="/images/ImageName.jpg" alt="Image">
</a>
CodePudding user response:
You have to put the pdf file in a folder. lets assume the folder is in the main directory and the folder name is pdf-folder and the pdf filename is my-pdf.pdf,
Then you can do this:
<a href="pdf-folder/mypdf.pdf"> The pdf-file</a>
And if this doesn't work you should try implementing javascript and then use createObjectUrl.
CodePudding user response:
<a href="examplefile.pdf" download > Download </a>
ref: https://www.wikihow.com/Make-a-File-Downloadable-from-Your-Website
Thank you, Have a great day ahead !