我有一个画布,用户可以通过它进行交互以对设计进行更改。在用户完成他的更改后,他可以提交他的设计和他的电子邮件ID。但要提交设计我将画布转换为图像使用http://www.nihilogic.dk/labs/canvas2image/发送电子邮件在HTML5画布上创建的图像
现在我想发送此图像以及用户的电子邮件ID。我如何直接发送这个图像而不让用户将它保存在他的本地系统上。
我有一个画布,用户可以通过它进行交互以对设计进行更改。在用户完成他的更改后,他可以提交他的设计和他的电子邮件ID。但要提交设计我将画布转换为图像使用http://www.nihilogic.dk/labs/canvas2image/发送电子邮件在HTML5画布上创建的图像
现在我想发送此图像以及用户的电子邮件ID。我如何直接发送这个图像而不让用户将它保存在他的本地系统上。
if(!empty($_POST['email'])){
$email=$_POST['email'];
$image=$_POST['legoImage'];
$headers="From:".$email."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
list($settings, $encoded_string) = explode(',', $image);
list($img_type, $encoding_method) = explode(';', substr($settings, 5));
if($encoding_method == 'base64'){
$file=fopen("images/newLego.png",'w+');
fwrite($file,base64_decode($encoded_string)) ;
fclose($file);
}
$my_file = "newLego.png";
$my_path = "images/";
$my_subject = "My Design";
$my_message = "Designed by ".$email;
mail_attachment($my_file, $my_path, "[email protected]", $email, $email, $email, $my_subject, $my_message);
}
我拿起mail_
attachment()函数here。
我想你需要一些javascript魔术,而且因为你已经使用了HTML5 canvas,所以这不应该是个问题。
因此,提交按钮上的onclick事件将向您的后端php邮件程序脚本发出ajax请求。
var strDataURI = oCanvas.toDataURL();
// returns "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACt..."
你只需要传递strDataURI作为参数。 现在,我想你也应该保存这些在你的数据库,以便电子邮件可以只包含这里面的图片标签:
<img src="http://www.yourdomain.com/generate_image.php?id=2" alt="Design #2" />
而且该generate_image.php脚本会做这样的事情
<?php
header('Cache-control: max-age=2592000');
header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 2592000));
// connect to db here ..
// $id = (int)$_GET['id']; "SELECT youtable WHERE id = '{$id}'"
// and the $image variable should contain "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACt..."
list($settings, $encoded_string) = explode(',', $image);
list($img_type, $encoding_method) = explode(';', substr($settings, 5))
header("Content-type: {$img_type}");
if($encoding_method == 'base64')
die(base64_decode($encoded_string)); // stop script execution and print out the image
else { // use another decoding method
}
@highstrike ...不幸的是,图像是在客户端创建的,我想将其发送到服务器端。它不在我的服务器 – Rohan210 2011-05-27 10:45:00
是的,我知道,这就是为什么你必须在提交按钮上做出这个Ajax请求,以便你从客户端传递“data:image/png; base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACt ...”到你的服务器。使用jQuery for ajax或其他库 – Highstrike 2011-05-27 10:49:10
好吧,我会看看那是怎么回事! – Rohan210 2011-05-27 10:51:21
问题是;如何将图像传送到服务器。据我所知,它仍然在客户端。 – 2011-05-27 10:35:00
@berry是的..我的问题在于将图像发送到服务器而不让用户处理它。 – Rohan210 2011-05-27 10:38:48