Return to Snippet

Revision: 35962
at November 15, 2010 13:39 by lorenz82


Initial Code
//CODE
import com.adobe.images.JPGEncoder;
import flash.display.BitmapData;
import flash.net.URLRequest;
import flash.net.URLRequestHeader;
import flash.net.URLRequestMethod;
import flash.net.navigateToURL;

var myBitmapData:BitmapData = new BitmapData(100, 100, false, 0xFFFFFF);
var jpgEncoder:JPGEncoder = new JPGEncoder(85);
var jpgStream:ByteArray = jpgEncoder.encode(myBitmapData);
var fileName:String='Name';
jpgStream.writeMultiByte("_s_"+fileName,"us-ascii");
var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
var request:URLRequest = new URLRequest("myJpgSaver.php");
request.requestHeaders.push(header);
request.method = URLRequestMethod.POST;
request.data = jpgStream;
navigateToURL(request, "_blank");	
myBitmapData.dispose();

//myJpgSaver.php
<?PHP
if (isset($GLOBALS["HTTP_RAW_POST_DATA"]))
{
	$parts=explode("_s_", $GLOBALS["HTTP_RAW_POST_DATA"]);
	$name=$parts[1];	
	$fp = fopen( $name.".jpg", 'wb' );	
	fwrite( $fp, $parts[0] );   
	fclose( $fp );		
}
?>

Initial URL

                                

Initial Description

                                

Initial Title
PHP image uploader from AS3

Initial Tags
php, data, image, post

Initial Language
ActionScript 3