upload images to a server from flash
Hi all, I'm developing a drawing application in flash and I want that when a user has finished his drawing, he can upload the file to a server.
I found a code on the web that does what I need, but when I upload the image to the server, there open another window and I don't want it does that, I want simply upload the file to the server without opening another window.
This is the AS code:
Code:
import com.adobe.images.JPGEncoder;
save_btn.addEventListener(MouseEvent.CLICK, guardarImg);
function guardarImg(e:MouseEvent):void
{
var canvasBmp:BitmapData = new BitmapData(360,300);
canvasBmp.draw(canvas);
var myEncoder:JPGEncoder = new JPGEncoder(100);
var byteArray:ByteArray = myEncoder.encode(canvasBmp);
//hacemos que se libere la memoria después de almacenar el objeto BitmapData.
canvasBmp.dispose();
var header:URLRequestHeader = new URLRequestHeader("Content-type","application/octet-stream");
var myDate:Date = new Date();
var timeNow:Number = myDate.getTime();
timeNow.toString();
var saveJPG:URLRequest = new URLRequest("savejpg.php?nombre=images/dibujo_" + myDate + ".jpg");
saveJPG.requestHeaders.push(header);
saveJPG.method = URLRequestMethod.POST;
saveJPG.data = byteArray;
navigateToURL(saveJPG, "_blank");
}
and this is the PHP file:
PHP Code:
<?php
if (isset($GLOBALS["HTTP_RAW_POST_DATA"]))
{
// get bytearray
$jpg = $GLOBALS["HTTP_RAW_POST_DATA"];
// add headers for download dialog-box
//header('Content-Type: image/jpeg');
$nombreArchivo = $_GET['nombre'];
$manejadorArchivo = fopen($nombreArchivo, 'w') or die("No se pudo escribir archivo");
fwrite($manejadorArchivo,$jpg);
fclose($manejadorArchivo);
}
?>
What can I do to avoid it from opening the window when I upload the picture? I've tried to delete this line:
Code:
Code:
navigateToURL(saveJPG, "_blank");
but if I delete it, the image didn't load. :confused:
thanks!