来自闪存的位图数据->;PHP->;电子邮件
我试图在Flash中拍摄一张电影剪辑的“截图”,使用as核心库JPGEncoder类将其编码为Jpg,然后将生成的ByteArray提交给PHP,并将图像嵌入MIME编码的电子邮件中 目前,我已经从Flash中保存了编码的ByteArray,这很好,所以问题在于如何从Flash发送到PHP。 我正在使用SwiftMailer发送一封以jpeg作为附件的复杂电子邮件。目前,脚本似乎在我从发送的数据构建附件时崩溃 以下是动作脚本:来自闪存的位图数据->;PHP->;电子邮件,php,flash,mime,Php,Flash,Mime,我试图在Flash中拍摄一张电影剪辑的“截图”,使用as核心库JPGEncoder类将其编码为Jpg,然后将生成的ByteArray提交给PHP,并将图像嵌入MIME编码的电子邮件中 目前,我已经从Flash中保存了编码的ByteArray,这很好,所以问题在于如何从Flash发送到PHP。 我正在使用SwiftMailer发送一封以jpeg作为附件的复杂电子邮件。目前,脚本似乎在我从发送的数据构建附件时崩溃 以下是动作脚本: trace("Sending Email"); var ro
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);
require_once'lib/swift_required.php';
$image=文件\u获取\u内容(“php://input");
$attachment=SwiftAttachment::newInstance($image,'submission.jpg','image/jpg')//setSubject(“您的主题”)
/*使用关联数组设置发件人地址*/
->setFrom(数组('info@battleforbrisbane.com.au“=>”布里斯班之战“)
/*将设置为具有关联数组的地址*/
->设置为(数组('jordaanm@gmail.com'))
/*给它一个身体*/
->setBody(“祝贺你!你提交给布里斯班战役的申请已收到”);
$message->attach($attachment)//发送($message);
这是一个专业的工作,所以任何帮助将不胜感激
更新:这不是SwiftAttachment,而是Swift_附件。缺少下划线,问题已解决,应用程序功能正常。感谢所有为我提供帮助的人您是否已验证编码图像是否有效 如果您有本地服务器或其他服务器,请在那里尝试 此外,您可以尝试将一个图像加载到flash中,并将其发送到服务器,然后查看是否有效,而不是发送生成的图像 至于如何从flash发送图像,请尝试以下方法
var request:URLRequest = new URLRequest( mailLoc );
request.contentType = 'application/octet-stream';
request.method = URLRequestMethod.POST;
request.data = bArray;
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, MailCompleteHandler);
loader.addEventListener( IOErrorEvent.IO_ERROR, _onImageError );
try
{
loader.load(request);
}
catch(error:Error)
{
trace("Unable to load URL");
}
private function _onImageError(e:IOErrorEvent):void {
trace("IOErrorEvent: ",e.type," : ",e.text)
}
对于php脚本,您可以先尝试保存文件
//bindary data.
$image_bytes = $GLOBALS["HTTP_RAW_POST_DATA"];
//change to whatever works for you
$file_name = "testfile.jpg";
$file_path = "../uploads/$file_name";
$file = fopen( $file_path, 'w+' );
if ( !fwrite( $file, $image_bytes ) ) {
return "Error writing to file: $file";
}
fclose( $file );
似乎问题一直是我在Swift_附件中遗漏了一个下划线。你不是很讨厌吗?这似乎是。我仍然希望看到1x1 GIF的原始输出,虽然在那里,而不是在这里。这是昨天问题的精练版本。一些小问题由您自己解决(现在使用SwiftMailer而不是手动编码)。然而,这个大问题还没有结束。就1x1像素而言,我从Flash->PHP发送的任何数据都拒绝写入(fwrite)或mime附加。
$image
是否有strlen
?感谢您的支持。我做了你建议的改变。闪存端未出现IO问题的标志。由于某些原因,PHP脚本不会编写该文件。奇怪…你尝试过不同的PHP设置吗?或者发送你之前上传的图像而不是生成的图像?对,那太糟糕了。但是,如果使用适当的“调试”方法,则很容易隔离出有问题的代码。基本上,把整个事情分解成更小的任务,测试一个,然后在上面构建下一个。当当前任务失败时,您知道可以将注意力集中在哪里。