【问题标题】:not able to convert canvas to image - server side无法将画布转换为图像 - 服务器端
【发布时间】:2016-05-08 23:31:10
【问题描述】:

无法将 html5 画布转换为服务器上的图像

我的代码:JavaScript

var testCanvas = document.getElementById("viewport");

    var canvasData = testCanvas.toDataURL("image/png");


    $.ajax({
        type: 'POST',
        url: 'process.php',
        data: {
            text1: canvasData
        },
        success: function(response) {

alert(response + '.png');
}

php 代码:process.php

<?php
function generateRandomString($length = 6) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
    return $randomString;
}


$rawData  = $_POST['text1'];
$filteredData = explode(',', $rawData);

$unencoded = base64_decode($filteredData[1]);
$dr = generateRandomString() ;

$fp = fopen('upload/' . $dr .'.png', 'w');
fwrite($fp, $unencoded);
fclose($fp); 

echo $dr;


?> 

我不明白我的代码有什么问题,我用谷歌搜索了很多,但没有找到任何有用的解决方案 我在 centos 上使用 nginx

【问题讨论】:

    标签: javascript php html canvas nginx


    【解决方案1】:

    我遇到了同样的问题,然后我发现我需要向我需要保存图像的目录授予写权限

    你可以通过这个命令来做:

    导航到文件夹和

    chmod -R 777-R 使其递归。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-05
      • 1970-01-01
      • 2020-05-14
      • 1970-01-01
      • 2018-06-26
      • 2017-09-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多