estoy haciendo un flash que me guarde una imagen....
pero ahora quiero que es imagen se guarde con nombre aleatorio, para no tener problemas que las fotos se remplaze... ejemplo... ejemplo01.jpg ejemplo10.jpg etc....
este es el codigo de flash
Cita:
/////////////////////////////////
//FUNCTION TO SAVE THE PICTURE //
/////////////////////////////////
function save_grab1(ev:MouseEvent)
{
// add bg
save_bg = new webcam_bg_mc;
save_bg.width = stage.stageWidth;
save_bg.height = stage.stageHeight;
save_bg.alpha = .8;
addChild(save_bg);
// add save box
save_holder = new save_holder_mc;
save_holder.x = stage.stageWidth/2 - vidWidth;
save_holder.y = stage.stageHeight/2 - vidHeight/2;
addChild(save_holder);
save_holder.save_btn.addEventListener(MouseEvent.M OUSE_OVER, s_use_over);
save_holder.save_btn.addEventListener(MouseEvent.M OUSE_OUT, s_use_out);
save_holder.save_btn.addEventListener(MouseEvent.C LICK, s_use_click);
save_holder.save_close_btn.addEventListener(MouseE vent.MOUSE_OVER, save_close_btn_over);
save_holder.save_close_btn.addEventListener(MouseE vent.MOUSE_OUT, save_close_btn_out);
save_holder.save_close_btn.addEventListener(MouseE vent.CLICK, save_close_btn_click);
}
// SAVE WINDOW SAVE BUTTON FUNCTION
function s_use_over(suo:MouseEvent)
{
suo.target.gotoAndStop(2);
}
function s_use_out(suo:MouseEvent)
{
suo.target.gotoAndStop(1);
}
function s_use_click(suc:MouseEvent)
{
if(im_W == 0)
{
im_W = mc.width;
im_H = mc.height;
}
// get image name
var image_name = save_holder.image_name.text;
// get email vars
var send_from = save_holder.send_from.text;
var send_to = save_holder.send_to.text;
var send_desc = save_holder.send_desc.text;
// call the saving function
save_grab2(mc, image_name, send_from, send_to, send_desc);
}
function save_grab2(pic_grab, image_name, send_from, send_to, send_desc)
{
// Create image with all the changes and save it
var bmd3:BitmapData = new BitmapData(im_W, im_H, false, 0x00000000);
bmd3.draw(pic_grab);
var bmd4:BitmapData = bmd3.clone();
var jpgEncoder:JPGEncoder = new JPGEncoder(90);
var jpgStream:ByteArray = jpgEncoder.encode(bmd4);
var header:URLRequestHeader = new URLRequestHeader("Content-type", "image/jpeg");
var jpgURLRequest:URLRequest = new URLRequest("image.php?imn=" + image_name + " " + send_from + "&sdt=" + send_to + "&ds=" + send_desc);
jpgURLRequest.requestHeaders.push(header);
jpgURLRequest.method = URLRequestMethod.POST;
jpgURLRequest.data = jpgStream;
navigateToURL(jpgURLRequest, "_blank");
}
// SAVE WINDOW CLOSE FUNCTION
function save_close_btn_over(so:MouseEvent)
{
so.target.gotoAndStop(2);
}
function save_close_btn_out(so:MouseEvent)
{
so.target.gotoAndStop(1);
}
function save_close_btn_click(sc:MouseEvent)
{
removeChild(save_holder);
removeChild(save_bg);
}
//FUNCTION TO SAVE THE PICTURE //
/////////////////////////////////
function save_grab1(ev:MouseEvent)
{
// add bg
save_bg = new webcam_bg_mc;
save_bg.width = stage.stageWidth;
save_bg.height = stage.stageHeight;
save_bg.alpha = .8;
addChild(save_bg);
// add save box
save_holder = new save_holder_mc;
save_holder.x = stage.stageWidth/2 - vidWidth;
save_holder.y = stage.stageHeight/2 - vidHeight/2;
addChild(save_holder);
save_holder.save_btn.addEventListener(MouseEvent.M OUSE_OVER, s_use_over);
save_holder.save_btn.addEventListener(MouseEvent.M OUSE_OUT, s_use_out);
save_holder.save_btn.addEventListener(MouseEvent.C LICK, s_use_click);
save_holder.save_close_btn.addEventListener(MouseE vent.MOUSE_OVER, save_close_btn_over);
save_holder.save_close_btn.addEventListener(MouseE vent.MOUSE_OUT, save_close_btn_out);
save_holder.save_close_btn.addEventListener(MouseE vent.CLICK, save_close_btn_click);
}
// SAVE WINDOW SAVE BUTTON FUNCTION
function s_use_over(suo:MouseEvent)
{
suo.target.gotoAndStop(2);
}
function s_use_out(suo:MouseEvent)
{
suo.target.gotoAndStop(1);
}
function s_use_click(suc:MouseEvent)
{
if(im_W == 0)
{
im_W = mc.width;
im_H = mc.height;
}
// get image name
var image_name = save_holder.image_name.text;
// get email vars
var send_from = save_holder.send_from.text;
var send_to = save_holder.send_to.text;
var send_desc = save_holder.send_desc.text;
// call the saving function
save_grab2(mc, image_name, send_from, send_to, send_desc);
}
function save_grab2(pic_grab, image_name, send_from, send_to, send_desc)
{
// Create image with all the changes and save it
var bmd3:BitmapData = new BitmapData(im_W, im_H, false, 0x00000000);
bmd3.draw(pic_grab);
var bmd4:BitmapData = bmd3.clone();
var jpgEncoder:JPGEncoder = new JPGEncoder(90);
var jpgStream:ByteArray = jpgEncoder.encode(bmd4);
var header:URLRequestHeader = new URLRequestHeader("Content-type", "image/jpeg");
var jpgURLRequest:URLRequest = new URLRequest("image.php?imn=" + image_name + " " + send_from + "&sdt=" + send_to + "&ds=" + send_desc);
jpgURLRequest.requestHeaders.push(header);
jpgURLRequest.method = URLRequestMethod.POST;
jpgURLRequest.data = jpgStream;
navigateToURL(jpgURLRequest, "_blank");
}
// SAVE WINDOW CLOSE FUNCTION
function save_close_btn_over(so:MouseEvent)
{
so.target.gotoAndStop(2);
}
function save_close_btn_out(so:MouseEvent)
{
so.target.gotoAndStop(1);
}
function save_close_btn_click(sc:MouseEvent)
{
removeChild(save_holder);
removeChild(save_bg);
}
y este es el codigo de php
Cita:
que tambien me pueda enviar al link correcto de la imagen <?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
// Set name for the image
if(!empty($_GET['imn']))
{
$image_name = $_GET['imn'];
}
else
{
$image_name = rand(0, 999999) / rand(1, 10);
}
$image_data = $GLOBALS['HTTP_RAW_POST_DATA'];
// put the image into the folder on the server
file_put_contents("upload/".$image_name.".jpg", $image_data);
// Check if we need to email the image
if(!empty($_GET['sdf']) and !empty($_GET['sdt']))
{
include('mail_it.php');
}
// Output the image
echo '<p>Your image is saved as: <i>'.$image_name.'.jpg</i></p>';
echo '<p><img src="upload/'.$image_name.'.jpg" alt="'.$image_name.'" /></p>';
/*
header( "Content-type: image/jpeg" );
echo $image_data;
*/
}
?>
if($_SERVER['REQUEST_METHOD'] == "POST")
{
// Set name for the image
if(!empty($_GET['imn']))
{
$image_name = $_GET['imn'];
}
else
{
$image_name = rand(0, 999999) / rand(1, 10);
}
$image_data = $GLOBALS['HTTP_RAW_POST_DATA'];
// put the image into the folder on the server
file_put_contents("upload/".$image_name.".jpg", $image_data);
// Check if we need to email the image
if(!empty($_GET['sdf']) and !empty($_GET['sdt']))
{
include('mail_it.php');
}
// Output the image
echo '<p>Your image is saved as: <i>'.$image_name.'.jpg</i></p>';
echo '<p><img src="upload/'.$image_name.'.jpg" alt="'.$image_name.'" /></p>';
/*
header( "Content-type: image/jpeg" );
echo $image_data;
*/
}
?>
Gracias de antemano