# AS3 PNGEncoder, Base64, and PHP

**URL:** https://forum.kirupa.com/t/as3-pngencoder-base64-and-php/324490
**Category:** flash
**Created:** [August 23, 2011, 11:57pm UTC](https://forum.kirupa.com/t/as3-pngencoder-base64-and-php/324490 "2011-08-23T23:57:57Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![laingm](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@laingm](https://forum.kirupa.com/u/laingm)
#### Post date: [August 23, 2011, 11:57pm UTC](https://forum.kirupa.com/t/as3-pngencoder-base64-and-php/324490/1 "2011-08-23T23:57:57Z")

</div>

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 [[COLOR=darkgreen]figure[/COLOR]](http://board.flashkit.com/board/showthread.php?t=824645#) 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…

```auto
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…

```auto
<?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?
