doyz51819 2015-06-15 18:30
浏览 80

使用隐藏输入发送PDF数据

I have an app which finally creates pdf from img using js. PDF data is inserted in hidden input. Next I send pdf to email address.

I have a problem with sending hidden input with pdf data via post.

While using free server it all works fine but on destination server hidden field is not received. Hidden field with just text works fine.

I checked max file upload data (62M).

  • 写回答

1条回答 默认 最新

  • douzhiling3166 2015-06-15 19:03
    关注

    HTML code:

        <div id="formPopUpDiv" style="display:none">    
        <form method="post" accept-charset="utf-8" name="form1">            
            <div class="formDiv">
                <div class="orderData">
                    <label>Imię i nazwisko</label>
                    <input type="text" id="nameTxt" name="name"/>
                    <label>Numer zamówienia</label>
                    <input type="text" id="orderNoTxt" name="orderNo"/>
                    <label>AdresEmail</label>
                    <input type="text" id="emailTxt" name="email_from"/>
                    <input name="hidden_data" id='hidden_data' type="hidden"/>      
    
                </div>
                <div class="orderButtons">
                    <input type="button" value='Wyślij' onclick="popupForm('formPopUpDiv', 300, 150, true)" id="sendButton" class="sendButton"/>
                    <input type="button" value='Odrzuć' onclick="hideForm('formPopUpDiv')" id="sendButton" class="sendButtonHide"/>
                </div>
            </div>
        </form>
    
    </div>
    

    JS code:

    if(isValid){            
            blanket_size(windowname);
            form_window_pos(windowname, width, height);
            toggle('blanket');
            toggle(windowname);
    
            drawDestImage(destinationCanvasArray, false);   
    
            var destCanvas = document.getElementById("destCanvasElement");
    
            var dataPDF = destCanvas.toDataURL("image/jpeg");
            var pdf = new jsPDF();
    
            pdf.addImage(dataPDF, 'JPEG', 0, 0, 210, 210);//210 is A4 width in mm
            //pdf.save("download.pdf");
    
            var pdfUrl = pdf.getDataURLString();
    
            document.getElementById('hidden_data').value = pdfUrl;
            //console.log(document.getElementById('hidden_data').value);
            var fd = new FormData(document.forms["form1"]);
    
            var xhr = new XMLHttpRequest();
            xhr.open('POST', 'upload_data.php', true);
    
            xhr.upload.onprogress = function(e) {
                if (e.lengthComputable) {
                    var percentComplete = (e.loaded / e.total) * 100;
                    //console.log(percentComplete + '% uploaded');
                }
            };
    
            xhr.onload = function() {
    
            };
            xhr.send(fd);
        }
    

    PHP code:

    <?php
    $upload_dir = "resultImg/";
    $img = $_POST['hidden_data'];
    $img = str_replace('data:application/pdf;base64,', '', $img);
    $img = str_replace(' ', '+', $img);
    $data = base64_decode($img);
    $file = $upload_dir . mktime() . ".pdf";
    $success = file_put_contents($file, $data);
    message $success ? $file : 'Unable to save the file.';
    
    srand((double)microtime()*1000000); 
    $znacznik = md5(uniqid(rand())); 
    
    
    $mojadres="pawel@sg2.pl";    
    $tytul=$_POST['name']." ".$_POST['orderNo']; 
    $tresclistu ="Podkładki"; 
    $nadawca =$_POST['email_from']; 
    $nadawca_mail=$_POST['email_from']; 
    
    $naglowki = "From: $nadawca <$nadawca_mail>
    "; 
    $naglowki .= "MIME-Version: 1.0
    "; 
    $naglowki .= "Content-Type: multipart/mixed;
    "; 
    $naglowki .= "\tboundary=\"___$znacznik==\""; 
    
    $x="--___$znacznik==
    "; 
    $x .="Content-Type: text/plain; charset=\"iso-8859-2\"
    "; 
    $x .="Content-Transfer-Encoding: 8bit
    "; 
    $x .="
    $tresclistu
    "; 
    
    
    $plik_nazwa_tmp = $file["tmp_name"]; 
    $plik_nazwa_oryginalna = $file["name"]; ;
    $plik_wielkosc = $file["size"]; 
    
    $x .="--___$znacznik==
    "; 
    $x .="Content-Type: application/octet-stream; name=\"attachment.pdf\"
    "; 
    $x .="Content-Disposition: attachment;
    "; 
    $x .=" filename=\"$tytul\".pdf
    "; 
    $x .="Content-Transfer-Encoding: base64
    
    "; 
    
    
    $x .= chunk_split(base64_encode($data)); 
    $x .="--___$znacznik==--
    "; 
    
    
    mail($mojadres,$tytul,$x,$naglowki); 
    
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集