File uploads with Adobe Flex and Zend AMF

Zend AMF is an implementation done in PHP to work with the communication protocol binary AMF (Action Message Format) and is part of ZendFramework. I had to implement a system to upload files that were a little different than what is typically used in Flash, with this feature had to be integrated into the Zend AMF.
Researching a little on the net, found a solution that was simpler than I thought based on that article with a few adjustments.
Begin with our gateway to be used as endpoint in Adobe Flex.
[PHP]
setProduction(false);

$server->setClass(‘UploadZendAMF’);

$server->setClassMap(‘FileVO’,”br.com.leonardofranca.vo.FileVO”);

echo($server->handle());
?>
[/PHP]
Now our VO properties with the file name and binaries.

[PHP]
fileName;
}

public function setFileName($fileName)
{
$this->fileName = $fileName;
}

public function getFileData()
{
return $this->fileData;
}

public function setFileData($fileData)
{
$this->fileData = $fileData;
}
}
?>
[/PHP]
Now our PHP class to be responsible for efetudar uploading.
[PHP]
getFileData();
file_put_contents( ‘C:\\apache\\htdocs\\images\\’ . $data->getFileName(), $fileData);//your dir
return true;
}
catch (Exception $e)
{
throw new Exception($e->getMessage());
}
}
}
?>
[/PHP]
Now let the view layer using Adobe Flex, we start with our VO.

[ACTIONSCRIPT3]
package br.com.leonardofranca.vo
{
import flash.utils.ByteArray;

[Bindable]
[RemoteClass(alias=”br.com.leonardofranca.vo.FileVO”)
public class FileVO
{
private var _fileName:String;
private var _fileData:ByteArray;

public function FileVO()
{
}

public function get fileName():String
{
return _fileName;
}

public function set fileName(value:String):void
{
_fileName = value;
}

public function get fileData():ByteArray
{
return _fileData;
}

public function set fileData(value:ByteArray):void
{
_fileData = value;
}

}
}
[/ACTIONSCRIPT3]
Now our mxml that will load the bytes from the file to send to the Zend AMF.
[MXML]















[/MXML]
Buy the source code $2.99

More source and PDFs click here

Was this article helpful? feel free to make a donation and help keep the blog in the air
ActionScript 3.0, Flex, PHP, ZendAMF

2 comments


  1. Allen

    Hi Leonardo,greate tutorial thanks.But how about the Flash IDE Version,can you point out me?Just via zendAMF and Flash(!Flex && !Flash Builder) to create upload images.Thanks!

  2. Sir Leonardo, thank you for making our research easier, with this tutorial File uploads with Adobe Flex and Zend AMF very Informative…

Leave a Reply