doukuang1897 2018-02-16 06:48
浏览 816

将jsPDF生成的pdf文件上传到php服务器

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";
 }
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?