Below is my javascript function that makes an ajax call via post. It sends a file location and the contents of a file to a php page that saves the file. The idea is so users can manage config file templates for a small application via the browser instead of manually logging into remote servers, making edits, and submitting the edits back to src control to be pulled into each application (it’s all automated on the page that this ajax call posts the data to).
My problem is with fileloc. I CANNOT get my ajax call to post the fileloc and keep the dir structure intact. I’ve tried escape(), encodeURI(), encodeURIComponent(), and JQuery’s versions of these functions. No matter what, my fileloc comes through on the saveConfigTemplates.php page as: “D:TestPHPconfigurationautomationtemplatesservernamefilename.cfg”. I’ve tried php’s decode and it doesn’t make a difference… it’s like the post loses all encoding and treats the single slashes as escape chars. Driving me nuts, any suggestions are appreciated.
function saveFile(){
var fileContents = $("#fileContent").val();
alert(fileContents);
var fileloc = "D:\TestPHP\configuration\automation\templates\servername\filename.cfg";
var fileconts = "fileloc="+encodeURIComponent(fileloc)+"&fileconts="+fileContents;
$.ajax({
type: "POST",
url: "saveConfigTemplates.php",
data: fileconts,
success: function(data) {
alert(data);
}
});
}
escape the backslashes: