=========
1。Flash8:
uploader.as
--------------------------------------------------------------------------------
import flash.net.FileReference; //调用上传控件,这个是必须的,要传文件就要用这个控件
var frToUpload:FileReference = new FileReference(); //实例化一个文件上传控件
var ofile:Object = new Object(); //定义对象侦听器,主要是侦听文件上传控件上面的事件
ofile.onSelect = function (fresele:FileReference):Void{
fileName = fresele.name;
fresele.upload(fileUploader.php); //这句是把文件传到哪个处理程序,这里用fileUploader.php来处理文件上传
}
//------------以上这段参数可以在flash的帮助里面找到查询关健字FileReference
ofile.onCancel = function (fresele:FileReference):Void{ // 当用户在选择文件对话框中点击取消之后触发的事件
trace("cancel");
}
frToUpload.addListener(ofile); //将侦听器绑定到上传控件中,这样侦听器才能生效
bt1.onPress = function() { //放一个按钮命名为bt1,用于调用browse方法(也就是选择文件的对话框)
_root.frToUpload.browse();
}
-------------------------
2.PHP简单后台实现。
fileUploader.php
-------------
<?php
//path to storage
$storage = 'userUploads';
//path name of file for storage
$uploadfile = "$storage/" . basename( INSERT:CONTENT:END FILES['Filedata']['name'] );
//if the file is moved successfully
if ( move_uploaded_file( INSERT:CONTENT:END FILES['Filedata']['tmp_name'] , $uploadfile ) ) {
echo( '1 ' . INSERT:CONTENT:END FILES['Filedata']['name']);
//file failed to move
}else{
echo( '0');
}
? >