简体   繁体   English

具有Base64和PHP的Flash AS3 PNGEncoder无法正常工作

[英]Flash AS3 PNGEncoder With Base64 and PHP Not Working

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. 我正在尝试将PNGEncoder与dynamicfash Base64一起使用,以将Base64字符串发送到PHP并保存PNG文件,但是由于某种原因,我无法弄清楚,PNG文件永远无法读取。 It is there and has a size (contains data) but cannot be opened by anything so is not a valid png file. 它在那里并且具有大小(包含数据),但是不能用任何东西打开,因此不是有效的png文件。 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代码...

<?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? 对我在这里做错的任何想法吗?

With FlashPlayer 10 (which has >95% adoption rate) you don't need to send the png data to a php page. 使用FlashPlayer 10(采用率> 95%),您无需将png数据发送到php页面。 Just use FileReference.save() instead. 只需使用FileReference.save()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM