I am uploading a pdf file generated by jsPDF to the php server. What I am missing here? How can I check the pdf file content before sending it?
In JS,
var doc = new jsPDF(parameters);
doc.addHTML($('#test')[0], 0, 0, {
}, function() {
pdf = doc.output('blob');
});
$.ajax({
url: 'upload.php',
type: 'post',
data: {data: pdf},
processData: false,
}).done(function (data) {
alert(data);
}).fail(function (xhr, status, err) {
alert(err);
});
And in php,
<?php
if(!empty($_POST['data'])){
$data = base64_decode($_POST['data']);
file_put_contents( "tmp/test.pdf", $data);
else {
echo "error";
}
?>