需要从Javascript代码中的html表在cpanel目录中创建csv文件



我可以在以下javascript代码的帮助下从html表下载csv文件;

function downloadCSV(csv, filename) {
var csvFile;
var downloadLink;
// CSV file
csvFile = new Blob([csv], {type: "text/csv"});
// Download link
downloadLink = document.createElement("a");
// File name
downloadLink.download = filename;
// Create a link to the file
downloadLink.href = window.URL.createObjectURL(csvFile);
// Hide download link
downloadLink.style.display = "none";
// Add the link to DOM
document.body.appendChild(downloadLink);
// Click download link
downloadLink.click();
}
function exportTableToCSV(filename) {
var csv = [];
var rows = document.querySelectorAll(".csv");
for (var i = 0; i < rows.length; i++) {
var row = []; 
cols = rows[i].querySelectorAll(".csvs");
// cols =   cols.replace(",","");
for (var j = 0; j < cols.length; j++) 
row.push(cols[j].innerText.replace(",",""));
csv.push(row.join(","));        
}
// Download CSV file //// now need to create file in cpanel dir.
downloadCSV(csv.join("n"), filename);
}

现在需要在cpanel目录中创建csv文件,但不能下载。请更改相同的代码,以便我在创建csv时使用它。

JavaScript是一种客户端语言,因此它不能执行任何与服务器有关的功能,因此需要PHP脚本才能执行。

最新更新