Flash AS3 PNGEncoder 与 Base64 和 PHP 不工作
我正在尝试利用 PNGEncoder 和dynamicfash Base64 将 Base64 字符串发送到 PHP 并保存 PNG 文件,但由于某种我无法弄清楚的原因,PNG 文件永远无法读取。它在那里并且有一个大小(包含数据),但无法被任何东西打开,所以不是一个有效的 png 文件。这是我的代码...
var target:MovieClip = new MovieClip();
target.graphics.beginFill(0xff0000,5.0);
target.graphics.drawRect(0,0,100,100);
target.graphics.endFill();
var bdata:BitmapData = new BitmapData(100, 100);
bdata.draw(target);
var stream:ByteArray = PNGEncoder.encode(bdata);
var byteArrayAsString:String = Base64.encodeByteArray(stream);
var request:URLRequest = new URLRequest("pngsave.php");
request.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.fileName = "testing.png";
variables.image = byteArrayAsString;
request.data = variables;
navigateToURL(request, "_blank");
以及 PHP 代码...
<?php
header('Content-Type: image/png');
header("Content-Disposition: attachment; filename=".$_POST['fileName']);
echo base64_decode($_POST["image"]);
?>
关于我在这里做错了什么有什么想法吗?
I am trying to utilize the PNGEncoder with the dynamicfash Base64 to send a Base64 String to PHP and save the PNG File but for some reason that i cannot figure out, the PNG file is never readable. It is there and has a size (contains data) but cannot be opened by anything so is not a valid png file. Here is my code...
var target:MovieClip = new MovieClip();
target.graphics.beginFill(0xff0000,5.0);
target.graphics.drawRect(0,0,100,100);
target.graphics.endFill();
var bdata:BitmapData = new BitmapData(100, 100);
bdata.draw(target);
var stream:ByteArray = PNGEncoder.encode(bdata);
var byteArrayAsString:String = Base64.encodeByteArray(stream);
var request:URLRequest = new URLRequest("pngsave.php");
request.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.fileName = "testing.png";
variables.image = byteArrayAsString;
request.data = variables;
navigateToURL(request, "_blank");
and the PHP Code...
<?php
header('Content-Type: image/png');
header("Content-Disposition: attachment; filename=".$_POST['fileName']);
echo base64_decode($_POST["image"]);
?>
Any ideas on what I am doing wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 FlashPlayer 10(采用率 >95%),您不需要将 png 数据发送到 php 页面。只需使用
相反,FileReference.save()
。With FlashPlayer 10 (which has >95% adoption rate) you don't need to send the png data to a php page. Just use
FileReference.save()
instead.