2014-10-29 2 views
0

다음 스크립트를 사용하여 html 캔버스를 png로 변환하고 클라이언트가 이미지를 서버에 저장하지 않고 다운로드하게합니다. 이 스크립트는 xampp과 서버 cuccfree.cc에서 작동했습니다. 그러나 동일한 스크립트가 서버에서 호스팅되지 않아도 작동하지 않습니다.base64 디코딩 된 이미지가 다운로드되지 않음

자바

  fname = fname || 'picture'; 

     var data = cnvs.toDataURL("image/png"); 
     data = data.substr(data.indexOf(',') + 1).toString(); 

     var dataInput = document.createElement("input") ; 
     dataInput.setAttribute("name", 'imgdata') ; 
     dataInput.setAttribute("value", data); 
     dataInput.setAttribute("type", "hidden"); 

     var nameInput = document.createElement("input") ; 
     nameInput.setAttribute("name", 'name') ; 
     nameInput.setAttribute("value", fname + '.png'); 

     var myForm = document.createElement("form"); 
     myForm.method = 'post'; 
     myForm.action = url; 
     myForm.appendChild(dataInput); 
     myForm.appendChild(nameInput); 

     document.body.appendChild(myForm) ; 
     myForm.submit() ; 
     document.body.removeChild(myForm) ; 

PHP가

<?php 
    # we are a PNG image 
    header('Content-type: image/png'); 

    # we are an attachment (eg download), and we have a name 
    header('Content-Disposition: attachment; filename="' . $_POST['name'] .'"'); 

    #capture, replace any spaces w/ plusses, and decode 
    $encoded = $_POST['imgdata']; 
    $encoded = str_replace(' ', '+', $encoded); 
    $decoded = base64_decode($encoded); 

    #write decoded data 
    echo $decoded; 
?> 

를 scipt하지만 난 자바 스크립트 기능에 할당 된 버튼을 클릭 할 때 얻는 출력된다. http://oi57.tinypic.com/2je1cva.jpg

어떻게하면이 오류를 해결할 수 있습니까 ??? ??? 제발 도와주세요 ....

답변

0

나는 당신이 함께 일하고있는 다른 서버의 php.ini에서 PHP 확장을 확인하기를 제안한다. 프로덕션 서버에 확장이 없을 수 있습니다.