I'm writing a web application that, among other things, allows users to upload files to my server. In order to prevent name clashes and to organize the files, I rename them once they are put on my server.
My question is, is there any way to specify the name of a file to be downloaded.? So a user uploads a file named 'abc.pdf' and I rename it to '10.pdf', but when they download it I want the browser to save the file as 'abc.pdf' by default. is there any way to do it?
I referred this question
How to set name of file downloaded from browser?
But in my case, I am opening pdf by in new tab from javascript. when clicking on pdf will get the id which is equal to the name stored in the server, with that id will refer DB and fetch actual name using ajax. But How will I rename the filename from id to actual name?
$(document).on('click', '.file', function (e) {
var id = this.id+'.pdf';
$.ajax({
url: "<?php echo base_url() ?>/Directorylist/files",
type: "POST",
datatype: 'json',
success: function (data) {
var actual_name = data;
var win = window.open();
win.location.href="http://localhost:8080/panExplorer/uploads/"+id+"";
},
});
});