Hi!
I’m starting to go mad here and really need some help from a php-wiz, (which I am not!).
I’va made a simple web page and are using json files to store data.
I had everything working fine on my localhost with xampp but found that the php scripts didn’t want to write to my json files once I put it up on an IIS Server.
I’ve spent the whole day now trying to figure this out and disovered that the PHP scripts aren’t even working on localhost anymore!
The PHP code lokes like this. I’ve tried both versions (commented out block) of doing it:
[php]
<?php
$myFile = "json/statistics.json";
$stringData = json_encode($_POST["data"]);
file_put_contents ( $myFile, $stringData, LOCK_EX );
/*
$myFile = "json/statistics.json";
var_dump(file_exists( $myFile ) );
$fh = fopen($myFile, "w") or die("can't open file");
$stringData = json_encode($_POST["data"]);
fwrite($fh, $stringData);
fclose($fh);
*/
?>
[/php]
And I’m calling the PHP with this bit of JavaScript
saveJson(countries, "php/save_countries_to_json.php");
function saveJson(object, file) {
console.log("Saving JSON data: " + JSON.stringify(object));
$.ajax
({
type: "POST",
dataType : 'json',
async: false,
url: file,
data: { data:object },
success: function () {console.log("Thanks!"); },
failure: function() {console.log("Error!");}
});
}
Would really need to fix this problem today so any help is more than apreciated!
Thanks!