Alright, I tried your idea. Below is a PHP object that I wrote to handle the SaveImage feature of my Flash application.
<code>
<?php
error_reporting(E_ALL);
ini_set('display_errors','On');
$newUser = new SaveImage();
class SaveImage
{
//a reference to thd facebook object
public $facebook;
//holds the app users uid
public $id;
//holds the selected users uid
public $targetUID;
//the byte array data
public $byteArray;
//holds a reference to the db connection
public $connection;
//the output that gets returned to flash
public $outputObject;
public function __construct()
{
//include the database connection
include 'database.php';
//include the php sdk
//include the facebook sdk library
require_once('facebook.php');
//instantiate a new Facebook Object, you must replace your APP_ID with your real apps app id. do the same for the secret.
$this->facebook = new Facebook(array(
'appId' => 'removed',
'secret' => 'removed',
'cookie' => true));
//store a reference to the db connection in this object
$this->connection = $connection;
//initialize the outputObject
$this->outputObject = new stdClass();
//attempt to get the current user
$this->id = mysqli_real_escape_string($this->connection, $this->facebook->getUser());
$this->byteArray = $this->getByteArray();
$this->targetUID = $this->getTargetUID();
if($this->targetUID != NULL)
{
//continue
if(isset($this->byteArray))
{
//create a filepatch where to put the file.
$filename = "wallImages/" . $this->targetUID . "_wallImage.png";
//use file put contents to put the file
$result = file_put_contents($filename, $this->byteArray);
$this->outputObject->result = "Sucess!";
}
}
echo json_encode($this->outputObject);
}
public function getByteArray()
{
return $_POST['byte_array'];
}
public function getTargetUID()
{
if(strlen($_POST['selectedWall']) > 0)
{
return mysqli_real_escape_string($this->connection, $_POST['selectedWall']);
} else
{
return NULL;
}
}
}
?>
</code>
It's kind of odd, but i'm getting the final output PNG file created, but it's only 1kb in size and doesn't open up in any image editors. It says the data might be corrupted when I try to open it.