php接收二进制文件转换成图片,php://input
$GLOBALS['HTTP_RAW_POST_DATA']
as3 代码
var bitmapData:BitmapData = new BitmapData(drawWidth,
drawHeight);//的到BitmapData
var myMatrix:Matrix = new Matrix(1, 0, 0, 1, drawWidth/ 2, drawHeight/ 2);//改变中心点
bitmapData.draw(Con_mc, myMatrix);//绘制位图数据
var encoder:JPGEncoder = new JPGEncoder(80);
var bytes:ByteArray = encoder.encode(bitmapData);//得到二进制位图数据
var request = new URLRequest("detail.php");
request.data = bytes;
request.method = URLRequestMethod.POST;
request.contentType = "application/octet-stream";
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, completeHandler);
loader.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
loader.load(request);//发送请求
//flash得到 php返回的数据代码
private function completeHandler(Evt:Event):void
{
var callBack:String = Evt.currentTarget.data;
}
detail.php代码
<?php
$filename="teststream.jpg";//要生成的图片名字
if
(!empty($GLOBALS["HTTP_RAW_POST_DATA"]))
{
$jpg =
$GLOBALS["HTTP_RAW_POST_DATA"];//得到post过来的二进制原始数据
$file =
fopen("cache/pic/".$filename,"w");//打开文件准备写入
fwrite($file,$jpg);//写入
fclose($file);//关闭
}
?>
$data = $GLOBALS['HTTP_RAW_POST_DATA'];
if(!empty($data)){
$now = date("YmdHis"); //给图片产生 名称
$path = "admin/uploads/"; //定义上传路径 他是相对于 detail.php 的文件路径
if(!file_exists($path.$now.".jpg")){
$fo = fopen($path.$now.".jpg","w");
if(fwrite($fo,$data) === false){
$flag = "0";
}else{
$flag = $now.".jpg";
}
echo $flag;exit;//将文件名称返回给flash
}