douqiang1910 2014-08-23 00:24
浏览 50
已采纳

在PHP上将Canvas另存为图像时出现500内部服务器错误

Trying to save Raphael Paper on Server as an Image I have following code:

$(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>

and on my process.php I have :

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

but I am getting 500 Internal Server Error from process.php

enter image description here

Can you please let me know why this is happening and how can I stop it?

Thanks

  • 写回答

1条回答 默认 最新

  • dtxq82489 2014-08-23 00:31
    关注

    Your error is coming from the server, not from javascript which runs in the browser. So the problem is in your php script.

    There you have a simple syntax error:

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

    Should be:

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

    By the way, when you get 500 errors, you should always check the server error log and / or display errors in php:

    ini_set('display_errors', 1);
    

    Possibly combined with something like:

    error_reporting(E_ALL | E_STRICT);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀