dsj0312 2011-03-24 03:53
浏览 51
已采纳

来自Flash的BitmapData - > PHP - >电子邮件

I'm trying to take a 'screenshot' of a movieclip in Flash, encode it as a Jpg using the AS Core Lib JPGEncoder class, then POST submit the resulting ByteArray to PHP, and embed the image in a MIME encoded email.

Currently, I've saved the encoded ByteArray from Flash, and that works fine, so the issue is in the sending from Flash to PHP. I'm using SwiftMailer to send a complex email with the jpeg as an attachment. Currently, the script seems to be crashing at the point where I build the attachment from the sent data.

Here's the Actionscript:

trace("Sending Email");
    var rootMC:MovieClip = MovieClip(root);
    var data1:BitmapData = new BitmapData(rootMC.width, rootMC.height); 
    data1.draw(rootMC);

    var en:JPGEncoder = new JPGEncoder(80);
    var bArray:ByteArray=   en.encode(data1);

var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");

    var request:URLRequest = new URLRequest();
    request.requestHeaders.push(header);
    request.url = mailLoc;//MailLoc is the URL of the PHP.
    request.method = URLRequestMethod.POST;
    request.data = bArray;
    var loader:URLLoader = new URLLoader();
    loader.dataFormat = URLLoaderDataFormat.BINARY;
    loader.addEventListener(Event.COMPLETE, MailCompleteHandler);
    try
    {
        loader.load(request);
    }
    catch(error:Error)
    {
        trace("Unable to load URL");
    }

And here is the PHP:

require_once 'lib/swift_required.php';  
$image = file_get_contents("php://input");  
$attachment = SwiftAttachment::newInstance($image, 'submission.jpg', 'image/jpg');//<--This line stuffs it  

$message = Swift_Message::newInstance()  
    /*Give the message a subject*/  
    ->setSubject('Your subject')  
    /*Set the from address with an associative array*/  
    ->setFrom(array('info@battleforbrisbane.com.au'=>'Battle for Brisbane'))  
    /*Set the to addresses with an associative array*/  
    ->setTo(array('jordaanm@gmail.com'))  
    /*Give it a body*/  
    ->setBody('Congratulations! You submission to Battle for Brisbane was received'); 
    $message->attach($attachment);//<--When the attachment above is commented out, so is this  

    $transport = Swift_SendmailTransport::newInstance();  
    $mailer = Swift_Mailer::newInstance($transport);  
    $mailer->send($message); 

This is for a professional job, so any help would be greatly appreciated.

Update: It's not SwiftAttachment, it's Swift_Attachment. Missing underscore, problem solved, application functional. Thanks to all who posted to help me with this

  • 写回答

2条回答 默认 最新

  • duannue2455 2011-03-30 21:33
    关注

    Seems that the issue all along was that I was missing an underscore in Swift_Attachment. Don't you just hate that?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line