dataurl图像下载在PHP [英] dataurl to image for download in php

查看:116
本文介绍了dataurl图像下载在PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用创建的图像画布并使用下面的脚本,

I'm creating image using canvas and using following script,

function getImage() {
    var canvas1 = document.getElementById("images");

    if (canvas1.getContext) {
        var ctx = canvas1.getContext("2d");
        var myImage = canvas1.toDataURL("image/jpg");
    }
    $('<form action="download.php" method="POST">' + 
    '<input type="hidden" name="aid" value="' + myImage + '">' +
    '</form>').submit();

}

在我的download.php文件,

And in my Download.php file is,

<?php $img = $_POST['aid']; 
    echo "<img src=".$img.">";
?>

它正确显示图像。但我想给的下载按钮,JPG格式或PDF格式。

it showing image correctly. But i wanna give download button with jpg format or pdf format.

我如何使用?

我用的 base64_de code(); 方式。但我不能解决的。

I used base64_decode(); method. But i cant solve.

帮我...

推荐答案

感谢所有。但我得到了回答使用,

Thanks for all. but I got answer using,

file_put_contents();

不过的事情,我不知道怎么用。最后,我是从这个<一个href=\"http://stackoverflow.com/questions/11511511/how-to-save-a-png-image-server-side-from-a-base64-data-string/11511605#11511605\">Answer.

答案是,

$data = 'data:image/png;base64,AAAFBfj42Pj4';

list($type, $data) = explode(';', $data);
list(, $data)      = explode(',', $data);
$data = base64_decode($data);

file_put_contents('/tmp/image.png', $data);

而我依然在等待下载按钮,图像/ PDF格式的选项。

But still i'm waiting for download button with option of image/pdf format.

这篇关于dataurl图像下载在PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆