Flex 2和PHP上传文件

[code]<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init();" width="200" height="150">
<mx:Script>
<![CDATA[
import flash.net.FileReference;
import mx.controls.Alert;
import mx.events.CloseEvent;
import flash.events.*;

private var file : FileReference;
private var uploadURL : URLRequest;

private function init() : void{
Security.allowDomain("*");
file = new FileReference();
file.addEventListener(ProgressEvent.PROGRESS, onProgress);
file.addEventListener(Event.SELECT, onSelect);
uploadURL = new URLRequest();
uploadURL.url = "http://localhost:8081/upload.php";
}

private function upload() : void{
var imageTypes:FileFilter = new FileFilter("Images (*.jpg, *.jpeg, *.gif, *.png)", "*.jpg; *.jpeg; *.gif; *.png");
var allTypes:Array = new Array(imageTypes);
file.browse(allTypes);
}

private function onSelect(e : Event) : void{
Alert.show("上传 " + file.name + " (共 "+Math.round(file.size)+" 字节)?", "确认上传",Alert.YES|Alert.NO,null,proceedWithUpload);
}

private function onProgress(e:ProgressEvent) : void{
lbProgress.text = " 已上传 " + e.bytesLoaded + " 字节,共 " + e.bytesTotal + " 字节";
}

private function proceedWithUpload(e : CloseEvent) : void{
if (e.detail == Alert.YES){
file.upload(uploadURL);
}
}
]]>
</mx:Script>

<mx:Canvas width="100%" height="100%">
<mx:VBox width="100%" horizontalAlign="center">
</mx:VBox>
<mx:Button label="上传文件" click="upload();" y="91"/>
<mx:Label id="lbProgress" text="上传" x="87.5" y="26"/>
</mx:Canvas>


</mx:Application>
[/code]

[code]
<!-- saved from url=(0014)about:internet -->
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>upload</title>
<body scroll="no">

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
id="fileupload" width="200" height="150"
codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
<param name="movie" value="fileupload.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#869ca7" />
<param name="allowScriptAccess" value="sameDomain" />
<embed src="fileupload.swf" quality="high" bgcolor="#869ca7"
width="200" height="150" name="fileupload" align="middle"
play="true"
loop="false"
quality="high"
allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer">
</embed>
</object>

</body>
</html>
[/code]

[code]<?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;
}
?>[/code]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值