As stated I am recieving no data through my $_POST. I am trying to pass multiple canvas dataURLs to the server to be stored as images. The data exists on the client but never makes it to the server. It saves a bunch of empty .PNGs which shows me that the code is being executed, just none of the data there.
Here is relevant info from my JavaScript file:
function saveImages(){
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "urlForPHP.php",
data: $('#form1').serialize(),
success: function (result) {
console.log("Success");
}
});
}
And here is my PHP file (for one image only, I have removed the loop to store multiple images for readability)
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);
$rest_json = file_get_contents("php://input");
$_POST = json_decode($rest_json, true);
$finalDest = "path/to/save/";
if (!is_dir($finalDest)) {
// dir doesn't exist, make it
mkdir($finalDest, 0777, true);
}
//save data
$file = base64_decode($_POST["image"]);
$success = file_put_contents($finalDest . $x . ".png", $file);
print $success ? $file : 'Unable to save the file.';
Thank you in advance, sorry if this has been solved before but I have done quite a bit of reading up on this and tried the solutions to similar answers and nothing has worked so far.
EDIT
Added HTML code, forgot to include my Form!
<form method="post" accept-charset="utf-8" name="form1">
<input name="boxTypeID" id="boxTypeID" type="hidden"/>
<input name="image" id="image" type="hidden"/>
<input type="button" name="send" onclick="saveImages()"/>
</form>