Saving images from flash to server using PHP
I am trying to save some images from Flash to Php by sending a jpgstream, capturing it in php and pushing it to a file. Not sure what I am doing wrong here.
I am putting all the images I need into an array like so: (history is just where I am keeping all the image data)
for each($value in history)
{
var jpgSource:BitmapData = new BitmapData ($value.sourceImg.width, $value.sourceImg.height);
jpgSource.draw(开发者_如何学JAVA$value.sourceImg);
var encoder:JPEGEncoder = new JPEGEncoder(100);
var jpgStream:ByteArray = encoder.encode(jpgSource);
var imgDetailArr:Array = new Array(jpgStream, $value.name);
imgArr.push(imgDetailArr);
}
And then i send that to PHP using a remote object and amfphp:
rmObj.saveUserImages( imgArr);
On the php side I am doing this:
function saveUserImages( $imgArr)
{
foreach($imgArr as $value)
{
ob_start();
/* output image as JPEG */
$image = imagecreatefromjpeg($value[0]);
header('Content-type: image/jpeg');
imagejpeg( $image );
/* save output as file */
ob_flush();
file_put_contents( "images", ob_get_contents() );
}
}
But this doesn't seem to do the trick. I have been going through a bunch of different tutes and code snippets, so maybe I just ogt something confused along the way. I have done this before though and don't remember it being this difficult.
You may be better off calling JS from Flash and pass a path to the file via AJAX. Then, use PHP to upload the files directly. PHP has support for file uploads from a hard drive.
Edit:
On second thought, try switching ob_flush
with the line after it. It looks like you are deleting your temporary data before saving it.
im no expert on flash but this seems to be doing what you are looking for ... thoughts?
http://henryjones.us/articles/using-the-as3-jpeg-encoder
精彩评论