Solved

Flash camera control using ActionScript and php to save photo

Posted on 2011-09-25
15
582 Views
Last Modified: 2012-05-12
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
Comment
Question by:uberGeekSupreme
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 6
15 Comments
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 36595185
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
 

Author Comment

by:uberGeekSupreme
ID: 36595782
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
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 36596260
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:uberGeekSupreme
ID: 36596854
how would a dump of variables help exactly?
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 36598417
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
 

Author Comment

by:uberGeekSupreme
ID: 36673204
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
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 36710386
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
 

Author Comment

by:uberGeekSupreme
ID: 36812898
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
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 36813730
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
 

Author Comment

by:uberGeekSupreme
ID: 36819149

does it really take 3 equal signs?

$_GET["q"] === aBc
0
 

Author Comment

by:uberGeekSupreme
ID: 36857481
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
 

Author Comment

by:uberGeekSupreme
ID: 36863616
nevermind.  I figured it out.   <?php echo($_GET['itemID']); ?>

0
 

Author Comment

by:uberGeekSupreme
ID: 36864247
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
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 36890933
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
 

Author Closing Comment

by:uberGeekSupreme
ID: 36912701
thanks so much, bud!!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question