[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Flash camera control using ActionScript and php to save photo

Posted on 2011-09-25
15
Medium Priority
?
587 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 111

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 111

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
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.

 

Author Comment

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

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 111

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 111

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 111

Accepted Solution

by:
Ray Paseur earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.
Suggested Courses

656 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