簡體   English   中英

在PHP上獲取500 Internal Server Error並將畫布另存為圖像

[英]Getting on 500 Internal Server Error On PHP saving Canvas as Image

嘗試將Raphael Paper在服務器上保存為圖像,我有以下代碼:

$(function() {

$("#printBtn").click(function() {

var svg1 = $("#map > svg").get();
var svg = $('#map').html().replace(/>\s+/g, ">").replace(/\s+</g, "<").replace(/<canvas.+/g,"");
// strips off all spaces between tags

canvg('cvs', svg, {        
ignoreMouse: true, 
ignoreAnimation: true
});  
var canvas  = document.getElementById('cvs');
var img = canvas.toDataURL("image/png");
});          
});     

});
</script>

在我的process.php上,我有:

<?php
$data = substr($_POST['imageData'], strpos($_POST['imageData'], ",") + 1);
$decodedData = base64_decode($data);
fclose();
echo "/canvas.png";

但我從process.php收到500 Internal Server Error

在此處輸入圖片說明

您能否讓我知道為什么會這樣,我如何才能阻止它?

謝謝

您的錯誤來自服務器,而不是瀏覽器中運行的javascript。 所以問題出在您的php腳本中。

那里有一個簡單的語法錯誤:

data = substr($_POST['imageData'], strpos($_POST['imageData'], ",") + 1);

應該:

$data = substr($_POST['imageData'], strpos($_POST['imageData'], ",") + 1);
^ here

順便說一句,當您收到500個錯誤時,應該始終檢查服務器錯誤日志和/或在php中顯示錯誤:

ini_set('display_errors', 1);

可能與以下內容組合:

error_reporting(E_ALL | E_STRICT);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM