Error calling PHP through JQuery to overwrite HTML file

60 Views Asked by At

I have a couple of arrays with string values:

var sites = [homehtml, evshtml, dhtml, registerhtml];
var names = ["pagehome.html", "pageevents.html", "pagedjs.html", "pageregister.html"];

So basically I've assigned each the values of a normal html file plus different things within body tags to differentiate:

var homehtml = "<html><head>...";

Now, I'm using a for loop to call a JQuery function to overwrite html files I have online:

for(var i = 0; i < sites.length; i++) {
    $.get("/cen3721/createsites.php", {site: sites[i], name: names[i]}, function(data){ alert(data)});          
}

The file createsites.phphas the following:

<?php
    if (isset($_GET['site']) && isset($_GET['name'])) {
        $site = $_GET['site'];
        $name = $_GET['name'];
        echo file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/cen3721/' . $name, $site);
    }
?>

Where cen3721 is a folder within my hosting space. This code has worked for me to overwrite a .txt file before (though I hadn't used variables as part of the file address. Is this wrong, or should I use another method to write to an HTML file? Thank you very much in advance

0

There are 0 best solutions below