0

http://www.taffatech.com/Paint.html

点击保存,然后点击下载按钮。我正在尝试让它下载图像并将其重命名,在我的代码中它是“myimage”,感谢您给我的任何帮助,谢谢!

错误:

Warning: Cannot modify header information - headers already sent by (output started at /home/content/29/10007129/html/taffatech/saveme.php:2) in /home/content/29/10007129/html/taffatech/saveme.php on line 4

Warning: Cannot modify header information - headers already sent by (output started at /home/content/29/10007129/html/taffatech/saveme.php:2) in /home/content/29/10007129/html/taffatech/saveme.php on line 7

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;
?>

js按钮:

$("#download").click(function() {
var cs = new CanvasSaver('http://taffatech.com/saveme.php');

cs.savePNG(canvas, 'myimage');
});

保存函数js:

function CanvasSaver(url) {

    this.url = url;

    this.savePNG = function(canvas, fname) {
        if(!canvas || !url) return;
        fname = fname || 'picture';

        var data = canvas.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) ;
};

}

谢谢!如果您需要更多信息,请询问!

4

1 回答 1

0

问题是php的第一行,php文件的开头不能有空行。谢谢大家。

于 2013-06-19T21:39:12.897 回答