php+flash文件上传

废话少说,先看flash代码,在flash中新建一个文档,放上两个button,一个progressbar组件:
import flash.net.FileReference;
import mx.controls.Alert;

var my_pb:mx.controls.ProgressBar;
var maxSize = 1000*1000*5;  // 文件大小限制:5M
// 设置进度栏模式
my_pb.mode = "manual";
my_pb.label = "上传进度:%1%";
// 进度栏增加前的最小数值
my_pb.minimum = 0;
//  进度栏停止前的最大值
my_pb.maximum = 100;
var increment_num: Number = my_pb.minimum;

var allTypes:Array = new Array();
var imageTypes: Object = new  Object();
imageTypes.description = "Images (*.jpg, *.jpeg, *.gif, *.png)";
imageTypes.extension = "*.jpg; *.jpeg; *.gif; *.png";
allTypes.push(imageTypes);

var textTypes: Object = new  Object();
textTypes.description = "Text Files (*.txt, *.rtf)";
textTypes.extension = "*.txt;*.rtf";
allTypes.push(textTypes);

var flvType: Object =new  Object();
flvType.description ="flv Files (*.flv)";
flvType.extension ="*.flv";
allTypes.push(flvType);

//  定义警告确认后的动作。
var myClickHandler:Function =  function (evt_obj: Object) {
if (evt_obj.detail == Alert.OK) {
trace("start stock app");
}
};

var listener: Object = new  Object(); 

listener.onSelect =  function(file:FileReference): Void {
trace("onSelect: " + file.name);
// if(!file.upload("http://localhost/upfiles/hlp.php")) {
//  trace("Upload dialog failed to open.");
// }
     if (file.size<=maxSize)
    {
       // strState.text = "您选择得文件:" + file.name + "\n";
      btnUpload.enabled =  true;
    } else
    {
      msg( "对不起您选择的文件太大!");
      btnUpload.enabled =  false;
    }
}

listener.onCancel =  function(file:FileReference): Void {
trace("onCancel");
}

listener.onOpen =  function(file:FileReference): Void {
trace("onOpen: " + file.name);
}

listener.onProgress =  function(file:FileReference, bytesLoaded: Number, bytesTotal: Number): Void {
trace("onProgress with bytesLoaded: " + bytesLoaded + " bytesTotal: " + bytesTotal);
    my_pb.setProgress ((bytesLoaded / bytesTotal) * 100, my_pb.maximum);
}

listener.onComplete =  function(file:FileReference): Void {
trace("onComplete: " + file.name);
    msg("上传完毕!");
}

listener.onHTTPError =  function(file:FileReference): Void {
trace("onHTTPError: " + file.name);
    msg("onHTTPError: " + file.name);
}

listener.onIOError =  function(file:FileReference): Void {
trace("onIOError: " + file.name);
    msg("onIOError: " + file.name);
}

listener.onSecurityError =  function(file:FileReference, errorString: String): Void {
trace("onSecurityError: " + file.name + " errorString: " + errorString);
    msg("onSecurityError: " + file.name + " errorString: " + errorString);
}

var fileRef:FileReference = new FileReference();
fileRef.addListener(listener);
this.btnBrowse.onRelease =  function () {
    fileRef.browse(allTypes);
};
this.btnUpload.onRelease =  function () {
     if(!fileRef.upload("http://localhost/upfiles/upfile3.php")) {
trace("Upload dialog failed to open.");
}
     //  显示警告对话框。

}
function msg(msgtxt: String) {
    Alert.show(msgtxt, "消息", Alert.OK , this, myClickHandler, "stockIcon", Alert.OK);
}
php文件很简单:
<?php
//  Flash 传递的文件表单 name 属性为 Filedata
$fileName =  $_FILES["Filedata"]["name"];
$file =  $_FILES["Filedata"]["tmp_name"];
$path = "uploadFiles/";
if ( move_uploaded_file( $file,  $path .  $fileName)){
//  echo 1;
} else{
//  echo 0;
}
?>
原文链接: http://hi.baidu.com/bob11000/blog/item/91d22e5c7cc2204ff9f2c064.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fancybit

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值