• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 595
  • Last Modified:

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.
0
uberGeekSupreme
Asked:
uberGeekSupreme
  • 9
  • 6
1 Solution
 
Ray PaseurCommented:
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
0
 
uberGeekSupremeAuthor Commented:
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.";
}
0
 
Ray PaseurCommented:
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
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
uberGeekSupremeAuthor Commented:
how would a dump of variables help exactly?
0
 
Ray PaseurCommented:
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
0
 
uberGeekSupremeAuthor Commented:
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;
0
 
Ray PaseurCommented:
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
0
 
uberGeekSupremeAuthor Commented:
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.
0
 
Ray PaseurCommented:
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
0
 
uberGeekSupremeAuthor Commented:

does it really take 3 equal signs?

$_GET["q"] === aBc
0
 
uberGeekSupremeAuthor Commented:
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>
0
 
uberGeekSupremeAuthor Commented:
nevermind.  I figured it out.   <?php echo($_GET['itemID']); ?>

0
 
uberGeekSupremeAuthor Commented:
oops.  hold on...

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

      mainswf.addParam("FlashVars", "itemID=<?php echo($_GET['itemID']); ?>");
0
 
Ray PaseurCommented:
This seems to be morphing from a question with an answer into a rambling dialog, and I will have to sign off after these answers.

does it really take 3 equal signs?
3 equal signs are used to test for identicality, which is greater than equality.  Please see the comparison operators and type comparison tables here:
http://us2.php.net/operators.comparison
http://us2.php.net/manual/en/types.comparisons.php

what is wrong with this? ... "itemID=<? $itemID ?>"
That assumes that the PHP "short tags" setting is enabled.  It's a bad idea to enable that for a variety of reasons, mostly related to XML.  The full PHP statement is the one I would use.  Parentheses are not needed with echo; there is no extra credit for adding unnecessary punctuation to the code.
"itemID=<?php echo $_GET['itemID']; ?>"

But I would not use the $_GET array directly as shown in this statement.  Instead I would acknowledge the fact that the $_GET array is external data, which is by definition tainted and a potential attack vector.  So I would filter and sanitize the values in $_GET before I used them in my script.  PHP has the filter_var() functions to help you with this.

You might want to learn about HEREDOC notation.  It is very useful for plugging PHP variables into longer strings like HTML, CSS, JavaScript.
http://us2.php.net/manual/en/language.types.string.php

I assume it's OK to pass FlashVars via this javascript approach, eh?
Maybe.  It depends on the sequence of what you need to make happen.  Here is the general order of things.
1. Client makes a request to the server
2. PHP script runs to create HTML, CSS, JavaScript, etc
3. PHP script writes headers and browser output containing HTML, CSS, JavaScript, etc.  End of PHP
4. Client receives the completed response from the server
5. Client browser loads the DOM, guided by the HTML and CSS, runs the JavaScript, renders a web page and starts the Flash animation.

Hope this helps, and good luck with your project.  As you manipulate variables in PHP, always remember that var_dump() is your friend!

Best, ~Ray
0
 
uberGeekSupremeAuthor Commented:
thanks so much, bud!!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 9
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now