Javascript 将HTML转换为PDF时自动保存到Cpanel中的预定义文件夹

Javascript 将HTML转换为PDF时自动保存到Cpanel中的预定义文件夹,javascript,jquery,html,Javascript,Jquery,Html,我有一个代码,可以将上面提到的div中由id调用的HTML转换为PDF,并打开一个弹出窗口将其保存在系统中 但是,我正在尝试将生成的pdf自动保存到托管cpanel文件夹中的预定义文件夹中 到目前为止,我的代码是: <script type="text/javascript">//<![CDATA[ window.onload=function(){ $('#downloadPDF').click(function () {

我有一个代码,可以将上面提到的div中由id调用的HTML转换为PDF,并打开一个弹出窗口将其保存在系统中

但是,我正在尝试将生成的pdf自动保存到托管cpanel文件夹中的预定义文件夹中

到目前为止,我的代码是:

  <script type="text/javascript">//<![CDATA[
    window.onload=function(){
        $('#downloadPDF').click(function () {
            domtoimage.toPng(document.getElementById('content2'))
                .then(function (blob) {
                    var pdf = new jsPDF('l', 'pt', [$('#content2').width(), $('#content2').height()]);

                    pdf.addImage(blob, 'PNG', 0, 0, $('#content2').width(), $('#content2').height());
                    pdf.save("test.pdf");

                    that.options.api.optionsChanged();
                });
        });
        }
  //]]></script>


    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/dom-to-image/2.6.0/dom-to-image.min.js" integrity="sha256-c9vxcXyAG4paArQG3xk6DjyW/9aHxai2ef9RpMWO44A=" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.5/jspdf.min.js"></script>

<div id="content2" style="background: #fff;border-bottom: 1px solid #ffffff;">
    <div class="tokenDet"
        style="padding: 15px;border: 1px solid #000;width: 80%;margin: 0 auto;position: relative;overflow: hidden;">
        <div class="title" style="text-align: center; color: green; border-bottom: 1px solid #000;margin-bottom: 15px;">
            <h2>Entrance Exam Hall Ticket</h2>
        </div>
        <div class="parentdiv" style="display: inline-block;width: 100%;position: relative;">
            <div class="innerdiv" style="width: 80%;float: left;">
                <div class="restDet">
                    <div class="div">
                        <div class="label" style="width: 30%;float: left;">
                            <strong>Name</strong>
                        </div>
                        <div class="data" style="width: 70%;display: inline-block;">
                            <span>John Test</span>
                        </div>
                        <div class="label" style="width: 30%;float: left;">
                            <strong>D.O.B.</strong>
                        </div>
                        <div class="data" style="width: 70%;display: inline-block;">
                            <span>17th April, 1995</span>
                        </div>
                        <div class="label" style="width: 30%;float: left;">
                            <strong>Address</strong>
                        </div>
                        <div class="data" style="width: 70%;display: inline-block; color: blue">
                            <span>P.S. Srijan Corporate Park, Saltlake, Sector 5, Kolkata-91</span>
                        </div>
                        <div class="label" style="width: 30%;float: left;">
                            <strong>Contact Number</strong>
                        </div>
                        <div class="data" style="width: 70%;display: inline-block;">
                            <span>xxx4563210</span>
                        </div>
                        <div class="label" style="width: 30%;float: left;">
                            <strong>Email Id</strong>
                        </div>
                        <div class="data" style="width: 70%;display: inline-block;">
                            <span>test@test.com</span>
                        </div>
                        <div class="label" style="width: 30%;float: left;">
                            <strong>Parent(s) Name</strong>
                        </div>
                        <div class="data" style="width: 70%;display: inline-block;">
                            <span>S. Test</span><br /><span>7896541230</span>
                        </div>
                        <div class="label" style="width: 30%;float: left;">
                            <strong>Exam Center</strong>
                        </div>
                        <div class="data" style="width: 70%;display: inline-block;">
                            <span>Institute of Engineering & Management</span>
                        </div>
                        <div class="label" style="width: 30%;float: left;">
                            <strong>Hall Number</strong>
                        </div>
                        <div class="data" style="width: 70%;display: inline-block;">
                            <span>COM-32</span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="sideDiv" style="width: 20%;float: left;">
                <div class="atts" style="float: left;width: 100%;">
                    <div class="photo" style="width: 115px;height: 150px;float: right;">
                        <img src="https://cdn1.iconfinder.com/data/icons/baby-and-kids-7/50/75-512.png"
                            style="width: 100%;" />
                    </div>
                    <div class="sign"
                        style="position: absolute;bottom: 0;right: 0;border-top: 1px dashed #000;left: 80%;text-align: right;">
                        <small>Self Attested</small>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<button class="btn btn-info" id="downloadPDF">Download PDF</button>
//
考场入场券
名称
约翰测验
D.O.B.
1995年4月17日
地址
P.S.Srijan企业园,盐湖城,5区,加尔各答-91
联系电话
xxx4563210
电子邮件Id
test@test.com
家长姓名
美国测试
7896541230 考试中心 工程与管理学院 大厅编号 COM-32 自我证明 下载PDF
上面的代码非常适合从HTML生成PDF,并允许用户将其保存在系统中,但我希望的是自动将其保存到托管文件夹中的文件夹中

以下是我通常用于将上传的文件保存到cpanel或托管文件夹的代码:-

<?php 

 include('db.php'); 

$name = $_POST['name'];
$file_1=($_FILES['file_1']['name']);

$conn = new mysqli ($servername, $dbusername, $dbpassword, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "INSERT INTO table (name, file)
VALUES ('$name', '$file_1')";

if ($conn->query($sql) === TRUE) {
$target_dir = "/parent/files/";

$target_file1 = $target_dir . basename($_FILES["file_1"]["name"]);
$uploadOk1 = 1;
$imageFileType1 = strtolower(pathinfo($target_file1,PATHINFO_EXTENSION));
if ($uploadOk1 == 0) {
    echo "ERROR";
// if everything is ok, try to upload file
} else {
    if (move_uploaded_file($_FILES["file_1"]["tmp_name"], $target_file1)) {
       header("Location: index.php");
    }
}
}
else {
    echo "ERROR" . $sql . "<br>" . $conn->error;
}
$conn->close();

?>