Add the code below to your post template. It shows the original file name and saves the download under that name instead of the random string.
<!-- Restore the original file name when downloading an attachment -->
<script>document.addEventListener("DOMContentLoaded",()=>{document.querySelectorAll("fieldset").forEach(f=>{let l=f.querySelector("legend"),t=l?.textContent?.trim(),a=f.querySelector("a");if(t&&a){a.textContent=t;a.setAttribute("download",t);l.textContent="Download file"}});});</script>By default, attachments downloaded from the template come down with a long random number for a name. With this in place you don't have to rename them by hand afterward — much handier.
(Note: in the admin panel the attachment name still looks the same, that jumble of digits. It only changes on the front end after the post is published.)
See it in action:
One more:
In the download model, make the downloaded file name match the title
Add the JS below under the "Final download page template." It saves the file under the post title, automatically appending the right extension, which saves you from that long random number:
<!-- Rename the downloaded file to match the post title -->
<script>document.addEventListener("DOMContentLoaded",function(){var t=(document.title.split(" - ")[0]||"download").trim(),e={"application/zip":".zip","application/x-rar-compressed":".rar","application/x-7z-compressed":".7z","application/gzip":".gz","application/x-tar":".tar","application/pdf":".pdf","application/msword":".doc","application/vnd.openxmlformats-officedocument.wordprocessingml.document":".docx","application/vnd.ms-excel":".xls","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":".xlsx","application/vnd.ms-powerpoint":".ppt","application/vnd.openxmlformats-officedocument.presentationml.presentation":".pptx","application/octet-stream":"","text/plain":".txt","image/jpeg":".jpg","image/png":".png","image/gif":".gif","image/webp":".webp","video/mp4":".mp4","audio/mpeg":".mp3","audio/wav":".wav","video/x-msvideo":".avi","application/x-msdownload":".exe"},n=document.querySelectorAll('a[href*="doaction.php?enews=DownSoft"]');for(var r=0;r<n.length;r++)!function(n){n.addEventListener("click",function(r){r.preventDefault();var a=n.href,o=new XMLHttpRequest;o.open("GET",a,!0),o.responseType="blob",o.onload=function(){if(200===o.status){var n=o.getResponseHeader("Content-Type")||"",r=e[n.toLowerCase()]||function(t){var e={0:".zip",1:".rar",2:".pdf",3:".docx",4:".7z",5:".tar",6:".xlsx",7:".pptx",8:".mp4",9:".mp3",10:".txt"};try{var n=t.match(/pathid=(\d+)/);return n?e[n[1]]||"":""}catch(t){return""}}(a)||".bin",i=t+r,c=o.response;if(window.navigator&&window.navigator.msSaveOrOpenBlob)window.navigator.msSaveOrOpenBlob(c,i);else{var d=URL.createObjectURL(c),l=document.createElement("a");l.href=d,l.download=i,document.body.appendChild(l),l.click(),document.body.removeChild(l),URL.revokeObjectURL(d)}}else alert("Download failed. Please try again.")},o.onerror=function(){alert("Something went wrong. Download failed.")},o.send()})}(n[r])});</script>
Comments No Comments