tags:

views:

58

answers:

3

Hi guys, I am trying to take a variable sent from flash, and save it to a spot on my web server using PHP, I have NO idea how to do this, and I can't seem to find code that works anywhere on the web, any help would be greatly appreciated, thanx!

+1  A: 
$my_value = $_REQUEST['my_variable_name'];
file_put_contents('path/to/file.jpg', $my_value, FILE_APPEND | LOCK_EX);

I am not sure what you mean by byteArray, anyway if you can treat this as raw data from jpeg, then you can grab it in one go and save it to a file. Actually you can do it with one line of code with

file_put_contents('path/to/file.jpg', $_POST['my_variable_name'], FILE_APPEND | LOCK_EX);
Majid
Thax for the reply, it seems to be writing the file to the specified location, but it is empty, the file size is 0kb, any idea on what could be causing this?
Well if the directory is writable, then it means `$_POST['my_variable_name']` is not returning anything. Change `POST` to `GET` in the code and test it with parameters on the url to check if it actually writes to the file if it receives any data. E.g. `http://host.com/jpg_maker.php?my_variable_name=test` and then in the file you should have `test`
Majid
I tried that, and it created a file called test.jpg on my web server, but it is still empty. I just tried adding headers to the code to prompt for a download, and that seems to work ok, but I need it to save automatically, sorry to be such a bother, but thank you for the help!
Ok, so I finally got it to work with this code!if ( isset ( $GLOBALS["HTTP_RAW_POST_DATA"] )) { $im = $GLOBALS["HTTP_RAW_POST_DATA"]; $fp = fopen($_GET['name'], 'wb'); fwrite($fp, $im); fclose($fp); echo "result=".$_GET['name']; } else echo 'result=An error occured.';Thanx alot for all the help!
+1  A: 

Here's an entry I submitted to the Flex Cookbook that addresses your specific question:

http://cookbooks.adobe.com/post_Creating_a__png_file_from_a_webcam_image-12732.html

Should have enough there to let you handle it.

Myk
Thanx for the comment, but I seem to have gotten it to work with the above mentioned code.
A: 

I finally got it to work with this code,

if ( isset ( $GLOBALS["HTTP_RAW_POST_DATA"] )) {

    $im =  $GLOBALS["HTTP_RAW_POST_DATA"];

    $fp = fopen($_GET['name'], 'wb');   
    fwrite($fp, $im);
    fclose($fp);

    echo "result=".$_GET['name'];

}  else echo 'result=An error occured.';

Thanx to everyone who posted and helped me to get this working!