0
votes

Hi I'm working on actionscript, saving a raw image from camera then POST with save.php then I want save.php echo back the variable which is a file name that have just generated by save.php to actionscript see this line: var urlParameter:String = "images/test_01.php?img=" + "myfileURL"; navigateToURL(new URLRequest(urlParameter), "_blank");

Thanks in advance

this is AS3 code

function onSaveJPG(e:Event):void{
    var myEncoder:JPGEncoder = new JPGEncoder(100);
    var byteArray:ByteArray = myEncoder.encode(bitmapData);

    var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");

    var saveJPG:URLRequest = new URLRequest("save.php");
    saveJPG.requestHeaders.push(header);
    saveJPG.method = URLRequestMethod.POST;
    saveJPG.data = byteArray;

    var urlLoader:URLLoader = new URLLoader();
    urlLoader.addEventListener(Event.COMPLETE, sendComplete);
    urlLoader.load(saveJPG);

    function sendComplete(event:Event):void{
        warn.visible = true;
        addChild(warn);
        warn.addEventListener(MouseEvent.MOUSE_DOWN, warnDown);
        warn.buttonMode = true;  
    } 


    function warnDown(e:MouseEvent):void{
        var urlParameter:String = "images/test_01.php?img=" + "myfileURL";
        navigateToURL(new URLRequest(urlParameter), "_blank");
        //  navigateToURL(new URLRequest("images/"), "_blank"); 
        //  +saveJPG:URLRequest 
        // navigateToURL(new URLRequest("images/test_01.php?img=+saveJPG:URLRequest"), "_blank");
        warn.visible = false;
    }

} // move onSave JPG
} close to here instead of after sendComplete

warn.visible = false;

this is save.php

<?php

if(isset($GLOBALS["HTTP_RAW_POST_DATA"])){ $jpg = $GLOBALS["HTTP_RAW_POST_DATA"]; $img = $GET["img"]; $filename = "images/poza". mktime(). ".jpg"; file_put_contents($filename, $jpg);

echo "thisPic=" . $filename; // echo $filename;

} else{ echo "Encoded JPEG information not received."; } ?>

1

1 Answers

0
votes

In your case you are just using mktime() for the file name, and images/poza is hard coded. You can post the file name along the jpeg data from flash, and when onSaveJPG is called you simply display the file name to the user.

Below is example of how you can send file_name.

var JPGFileName = YOUR TIME FUNCTION
var saveJPG:URLRequest = new URLRequest("save.php?file_name=" + JPGFileName);
saveJPG.requestHeaders.push(header); 
saveJPG.method = URLRequestMethod.POST; saveJPG.data = byteArray;