【发布时间】:2011-07-21 20:04:49
【问题描述】:
我正在尝试在 Flash 中拍摄电影剪辑的“屏幕截图”,使用 AS Core Lib JPGEncoder 类将其编码为 Jpg,然后 POST 将生成的 ByteArray 提交给 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('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);
这是一份专业工作,因此我们将不胜感激。
更新:这不是 SwiftAttachment,而是 Swift_Attachment。缺少下划线,问题已解决,应用程序功能正常。感谢所有发帖帮助我解决此问题的人
【问题讨论】:
-
这似乎是an exact duplicate of your question yesterday。我仍然希望看到 1x1 GIF 的原始输出,虽然在那边,而不是在这里。
-
这是昨天问题的精炼版本。一些小问题由您自己解决(现在使用 SwiftMailer 而不是手动编码)。然而,大问题还没有结束。就 1x1 像素而言,我从 Flash->PHP 发送的任何数据都拒绝写入 (fwrite) 或 mime attach。
-
$image有strlen吗?