<form id="download" class="download_action" method="POST">
<input type="hidden" name="action" value="download_action">
<label for="url">Please enter the URL you would like to save as a file:</label>
<input id="url" class="text mr-3" name="keyword" type="text">
<input class="submit" title="Save target as" type="submit" value="Save target as">
<div class="tool-target" style="padding-bottom: 10px;"> </div>
<div id="return"> </div>
<input type="hidden" id="_wpnonce" name="_wpnonce" value="5c9a47c6d6" /><input type="hidden" name="_wp_http_referer" value="/tools/download-link-generator" />
It seems to be a server-side solution, but I don’t have much information about servers and how they do it. I wonder how it works exactly. Can similar projects be built on GitHub Pages, or do I need paid hosting and a server plus a vast knowledge of running it?
Server receives form.
Server gets url.
Server probably checks some things.
Server gets file contents
Server sends appropriate header for “this is a download”
Server pastes file contents
Server sends to browser.
Why do this instead of just… going to the URL? shrug
I’m not clear what it is you want to do.
Are you wanting to replicate the “Download link generator” form and have your own like it?
Or are you wanting to simply create a link yourself that will force download?
I don’t know a reliable way of doing it purely with client side code. There is the download attribute that can be put in an anchor, but it won’t necessarily work.
Ordinarily if the anchor links to a file type that can be opened in the browser, that’s what happens by default. But the user has the option of right-clicking and choosing to “save as”.
To force a download you need to put that in the HTTP headers, which you will do from the server. for example in PHP you may do it like this:- https://www.php.net/manual/en/function.header#example-4531