Flex使用AMFPHP下载文件
有人知道是否可以使用AMFPHP下载文件吗?我发现了一些使用php直接下载的示例。如果是,举例说明?我有一个使用AMFPHP上传文件的例程,但我没有在网上找到使用AMFPHP下载的示例Flex使用AMFPHP下载文件,php,actionscript-3,apache-flex,air,amfphp,Php,Actionscript 3,Apache Flex,Air,Amfphp,有人知道是否可以使用AMFPHP下载文件吗?我发现了一些使用php直接下载的示例。如果是,举例说明?我有一个使用AMFPHP上传文件的例程,但我没有在网上找到使用AMFPHP下载的示例 提前谢谢。请用ByteArray试试。差不多 按数组返回新的Amfphp\u核心\u Amf\u类型($data) 我找到了这篇文章:。基于此,我制作了自己的版本,因为我的服务是通过service-config.xml定义的,定义方式见amfphp文档第节 服务器端: 如果您已经知道如何配置网关以访问服务类和值对
提前谢谢。请用ByteArray试试。差不多 按数组返回新的Amfphp\u核心\u Amf\u类型($data) 我找到了这篇文章:。基于此,我制作了自己的版本,因为我的服务是通过service-config.xml定义的,定义方式见amfphp文档第节 服务器端: 如果您已经知道如何配置网关以访问服务类和值对象类,那么以下是两个类: ValueObject类:
<?php
class FileVO {
public $filename;
public $filedata;
// explicit actionscript class
var $_explicitType = "remoting.vo.FileVO";
}
?>
正在上载文件的组件:
<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:net="flash.net.*">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<net:FileReference id="fileReference"
select="select_handler(event)"
complete="complete_handler(event);"
/>
<s:RemoteObject id="ro"
destination="amfphp"
source="RemoteFile"
result="handleResult(event)"
fault="Alert.show('Error ! ')"/>
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
import remoting.vo.FileVO;
public function handleResult(event:ResultEvent):void{
Alert.show('the server said : ' + event.result);
}
private function btn_click(evt:MouseEvent):void {
fileReference.browse();
}
private function select_handler(evt:Event):void{
fileReference.load();
}
private function complete_handler(evt:Event):void{
var data:ByteArray = new ByteArray();
var file:FileVO;
//Read the bytes into bytearray var
fileReference.data.readBytes(data, 0, fileReference.data.length);
// Create a new FileVO instance
file = new FileVO();
file.filename = fileReference.name;
file.filedata = data;
ro.upload(file);
}
private function onEvent(evt:Event):void {
Alert.show(evt.toString(), evt.type);
}
]]>
</fx:Script>
<s:Button id="btn" label="Browse to Upload" click="btn_click(event);" />
</s:Group>
对我来说很有效!至少在我的开发服务器上。注意这里的安全漏洞。你需要提供某种形式的保护,以防止任何滥用
package remoting.vo
{
import flash.utils.ByteArray;
[RemoteClass(alias="FileVO")]
public class FileVO{
public var filename:String;
public var filedata:ByteArray;
public function FileVO(){
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:net="flash.net.*">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<net:FileReference id="fileReference"
select="select_handler(event)"
complete="complete_handler(event);"
/>
<s:RemoteObject id="ro"
destination="amfphp"
source="RemoteFile"
result="handleResult(event)"
fault="Alert.show('Error ! ')"/>
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
import remoting.vo.FileVO;
public function handleResult(event:ResultEvent):void{
Alert.show('the server said : ' + event.result);
}
private function btn_click(evt:MouseEvent):void {
fileReference.browse();
}
private function select_handler(evt:Event):void{
fileReference.load();
}
private function complete_handler(evt:Event):void{
var data:ByteArray = new ByteArray();
var file:FileVO;
//Read the bytes into bytearray var
fileReference.data.readBytes(data, 0, fileReference.data.length);
// Create a new FileVO instance
file = new FileVO();
file.filename = fileReference.name;
file.filedata = data;
ro.upload(file);
}
private function onEvent(evt:Event):void {
Alert.show(evt.toString(), evt.type);
}
]]>
</fx:Script>
<s:Button id="btn" label="Browse to Upload" click="btn_click(event);" />
</s:Group>