uberGeekSupreme
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.
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.
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_RA W_POST_DAT A"])){
$jpg = $GLOBALS["HTTP_RAW_POST_DA TA"];
$img = $_GET["img"];
$filename = "images/poza_". mktime(). ".jpg";
file_put_contents($filenam e, $jpg);
} else{
echo "Encoded JPEG information not received.";
}
if(isset($GLOBALS["HTTP_RA
$jpg = $GLOBALS["HTTP_RAW_POST_DA
$img = $_GET["img"];
$filename = "images/poza_". mktime(). ".jpg";
file_put_contents($filenam
} 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
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
ASKER
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($filenam e, $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
file_put_contents($filenam
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
ASKER
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.pus h(header);
saveJPG.method = URLRequestMethod.POST;
saveJPG.data = byteArray;
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.pus
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
Given the URL /path/to/script.php?q=aBc
You will find this variable: $_GET["q"] === aBc
ASKER
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
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
ASKER
does it really take 3 equal signs?
$_GET["q"] === aBc
ASKER
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.sw f", "main", "700", "400", "9", "#ffffff");
mainswf.addParam("scale", "noscale");
mainswf.addParam("wmode", "window");
mainswf.addParam("allowFul lScreen", "true");
mainswf.addParam("FlashVar s", "itemID=<? $itemID ?>");
//mainswf.addVariable("req uireLogin" , "false");
mainswf.write("flashArea") ;
</script>
<?php
$itemID = $_GET['itemID'];
?>
.
.
.
<script type="text/javascript">
var mainswf = new SWFObject("take_picture.sw
mainswf.addParam("scale", "noscale");
mainswf.addParam("wmode", "window");
mainswf.addParam("allowFul
mainswf.addParam("FlashVar
//mainswf.addVariable("req
mainswf.write("flashArea")
</script>
ASKER
nevermind. I figured it out. <?php echo($_GET['itemID']); ?>
ASKER
oops. hold on...
I assume it's OK to pass FlashVars via this javascript approach, eh?
mainswf.addParam("FlashVar s", "itemID=<?php echo($_GET['itemID']); ?>");
I assume it's OK to pass FlashVars via this javascript approach, eh?
mainswf.addParam("FlashVar
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks so much, bud!!
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