来自 Flash 的位图数据 -> PHP->电子邮件
我正在尝试在 Flash 中截取影片剪辑的“屏幕截图”,使用 AS Core Lib JPGEncoder 类将其编码为 Jpg,然后将生成的 ByteArray POST 提交到 PHP,并将图像嵌入 MIME 编码的电子邮件中。
目前,我已经从 Flash 保存了编码的 ByteArray,并且工作正常,因此问题出在从 Flash 发送到 PHP 的过程中。 我正在使用 SwiftMailer 发送一封复杂的电子邮件,并以 jpeg 作为附件。目前,在我根据发送的数据构建附件时,脚本似乎崩溃了。
这是动作脚本:
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");
}
这是 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('[email protected]'=>'Battle for Brisbane'))
/*Set the to addresses with an associative array*/
->setTo(array('[email protected]'))
/*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);
这是一项专业工作,因此我们将不胜感激。
更新:这不是 SwiftAttachment,而是 Swift_Attachment。缺少下划线,问题已解决,应用程序功能正常。感谢所有发帖帮助我的人
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('[email protected]'=>'Battle for Brisbane'))
/*Set the to addresses with an associative array*/
->setTo(array('[email protected]'))
/*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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否已验证编码图像是否有效?
如果您有本地服务器或不同的服务器,请在那里尝试。
此外,您可以尝试将一张图像加载到闪存中并将其发送到服务器,看看是否有效,而不是发送生成的图像。
至于如何从flash发送图像,试试这个
对于php脚本,你可以先尝试保存文件。
Have you verified that the encoded image is a valid one?
If you have a local server or a different server try it there.
Also, you can try to load one image into your flash and send that to the server and see if that works, instead of sending a generated image.
As for how to send the image from flash, try this
And for the php script, you can try first to save the file.
似乎问题一直是我在 Swift_Attachment 中缺少下划线。你不就是讨厌这样吗?
Seems that the issue all along was that I was missing an underscore in Swift_Attachment. Don't you just hate that?