Link to home
Start Free TrialLog in
Avatar of uberGeekSupreme
uberGeekSupremeFlag for United States of America

asked on

Flash camera control using ActionScript and php to save photo

I have a Adobe Flash-based photo taking control.  it works fine on a linux host but fails on Windows (IIS).   the folder was set to the equivalent of "chmod 777" on the IIS box but simply does not save the JPGencoded photo captured by ActionScript within the photo booth SWF.
surely considering how ubiquitous php is (regardless of merit) there must be a way to set it up properly for a simple php script to save the image to a JPG file.
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

What is the question?  

Do you need to know how to write a file in PHP?  If so, this function can be helpful.
http://php.net/manual/en/function.file-put-contents.php
Avatar of uberGeekSupreme

ASKER

yes, the PHP script is using file_put_contents (see below).  does PHP have to be running on linux to work properly?  is there some trick to make it work under IIS?


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);
} else{
      echo "Encoded JPEG information not received.";
}
PHP does not need Linux to work properly.  The overwhelming  majority of PHP installations use Linux, but there is nothing inherent in Windows that would necessarily cripple PHP.  And there are lots of IIS installations of PHP.  Don't worry about that part, at least not for now.

Instead, use some data visualization techniques.  Use var_dump() to print out the contents of your variables.  It will tell you a lot about what is going on!
http://php.net/manual/en/function.var-dump.php

HTH, ~Ray
how would a dump of variables help exactly?
Here is an example to illustrate the concept of looking at variables.  In the segment of code posted above, there is this line:

file_put_contents($filename, $jpg);

All by itself that line of code raises three important questions.

How do you know what the $filename variable contains?  How do you know what the $jpg variable contains?  How do you know whether file_put_contents() worked or not?  The answers to these questions are available if you visualize the variables.  You can use var_dump() to print out variables.  You can test the return code from file_put_contents() to see if it worked.  This man page and the added note seems like it would be important:
http://php.net/manual/en/function.file-put-contents.php#101349

You might also want to run phpinfo() on both of the systems and compare the outputs carefully to see if you are relying on any environmental variables that are different between the systems.  For example, you might want to look at the setting of this:
http://php.net/manual/en/ini.core.php#ini.always-populate-raw-post-data

See also: http://php.net/manual/en/reserved.variables.httprawpostdata.php
thanks.  could you help out with a little AS, please?

how would I pass an URL parm on to this php script?  I know I can pass a parm into the SWF but how is that referenced and appended to "save.php"?

      var saveJPG:URLRequest = new URLRequest("save.php");
      saveJPG.requestHeaders.push(header);
      saveJPG.method = URLRequestMethod.POST;
      saveJPG.data = byteArray;
That does not look like a PHP script to me.  But the URL parameters work like this:

Given the URL /path/to/script.php?q=aBc

You will find this variable: $_GET["q"] === aBc
pardon the error.  I was wanting to know how to reference and pass a URL parm in ActionScript and pass it on to the PHP.
Just a guess, but this might be correct:

var saveJPG:URLRequest = new URLRequest("save.php?q=aBc");

Maybe this can help:
http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7f9d.html

does it really take 3 equal signs?

$_GET["q"] === aBc
what is wrong with this?  I define $itemID and set it to the query string value then reference it in passing FlashVars...

<?php
$itemID = $_GET['itemID'];
?>
.
.
.
  <script type="text/javascript">
      var mainswf = new SWFObject("take_picture.swf", "main", "700", "400", "9", "#ffffff");
      mainswf.addParam("scale", "noscale");
      mainswf.addParam("wmode", "window");
      mainswf.addParam("allowFullScreen", "true");
      mainswf.addParam("FlashVars", "itemID=<? $itemID ?>");
      //mainswf.addVariable("requireLogin", "false");
      mainswf.write("flashArea");
      
  </script>
nevermind.  I figured it out.   <?php echo($_GET['itemID']); ?>

oops.  hold on...

I assume it's OK to pass FlashVars via this javascript approach, eh?

      mainswf.addParam("FlashVars", "itemID=<?php echo($_GET['itemID']); ?>");
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks so much, bud!!