这两个月在写一个CMS系统,很久没上来写过东西了,前几天公司的项目中要写一个外围程序,现在做好了,上来发个思路。为自己作备忘记,也当为有相关需求的朋友作参考。
需求:FLASH画好一幅图片后,传给PHP,PHP把图片用发送到客户的邮箱中。
php服务端代码
<?php
$data=$GLOBALS['HTTP_RAW_POST_DATA'];
$img=new Image();
if ($data){
$picurl=$img->createImage($data);
if ($picurl){
echo $picurl;
}else {
echo "error";
}
}else {
$pic=$_REQUEST['pic'];
$fromemail=$_REQUEST['fromEmial'];
$toemail=$_REQUEST['toEmail'];
echo "you send a email form $fromemail to $toemail ,pic is $pic";
}
class Image{
function createImage($data){
$now = date("YmdHis");
$path = "../upload/";
if(!file_exists($path.$now.".png")){
$fo = fopen($path.$now.".png","w");
if(!fwrite($fo,$data)){
return false;
}else{
return $now;
}
}
}
}
?>
FLASH端部分代码如下
var bmpData:BitmapData = new BitmapData(mc.width/3,mc.height,false,0xff0000);
var _Matrix:Matrix=new Matrix();
_Matrix.translate(mc.width/3/2,mc.height/2);
bmpData.draw(mc,_Matrix);
//************用于测试*******************
/*var map:Bitmap=new Bitmap(bmpData);
map.x=100
map.y=100
map.alpha=0.6
theStage.addChild(map);*/
//******************************************
request.url=String(data_xml.imgSave.emailBtn);
request.method = URLRequestMethod.POST;
var pngBytes:ByteArray = PNGEncoder.encode(bmpData);
var sendImg_loader:URLLoader =new URLLoader();
request.contentType = "application/octet-stream";
request.data =pngBytes;
sendImg_loader.addEventListener(Event.COMPLETE, sndImgComplete);
sendImg_loader.addEventListener(IOErrorEvent.IO_ERROR, sndImgError);
sendImg_loader.load(request);
这里上传不了附件,我会在下载中把附件发上去