Hi. Anyone knows how to pass a variable from FLASH to PHP?
I’m trying to upload an image through the URLRequest and pass a unique name for each file.( I want to store the name elsewhere and need flash to know the name of the file.)
Since I’m using the request.data for the ByteArray of the image, I read that I can’t use the URLVariables to pass any other variables.
It is almost working, except for the filename.
AS3 function calling the request and query string:
function uploadTheImage(GuidName:String):void
{
//create image
var stage_snapshot:BitmapData = new BitmapData(imgprev.width, imgprev.height);
stage_snapshot.draw(imgprev);
//create imagebyteArray
var encoded_jpg:JPGEncoder = new JPGEncoder(100);
var jpg_binary:ByteArray = encoded_jpg.encode(stage_snapshot);
var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream");
var request:URLRequest = new URLRequest("saveJpeg.php?filestring="+GuidName);
request.requestHeaders.push(header);
request.method = URLRequestMethod.POST;
request.data = jpg_binary;
var loader:URLLoader = new URLLoader();
configureListeners(loader);
loader.load(request);
}
and this is the PHP file, I don’t know what is wrong with it? and since it’s not in a browser I have no clue how to debugg it.
<?php
$jpg =$GLOBALS["HTTP_RAW_POST_DATA"];
//$filestring = getenv($QUERY_STRING);//$QUERY_STRING;
//$filename = 'upload/'.date('r').'.jpg';
$filestringer = $_REQUEST['filestring'];//$_GET['filestring'];
//$filename = 'upload/'.echo($filestringer) .date('r').'.jpg';
$filename = 'upload/'.echo($filestringer) .'.jpg';
file_put_contents($filename, $jpg);
?>