upload.as:
package
{
import flash.display.*;
import flash.net.*;
import flash.events.*;
import flash.text.*;
import flash.ui.*;
import fl.controls.List;
import fl.controls.ScrollBarDirection;
import fl.controls.TileList;
import fl.data.DataProvider;
//网络应用
import flash.net.URLRequest;
import flash.net.URLRequestHeader;
import flash.net.URLRequestMethod;
public class Upload extends Sprite
{
var base_url:String = './';
var upload_btn:Btn = new Btn;/////UPLOAD_BTN
var pending_files_array:Array;
var upload_details_array:Array;
var upload_details_contain:TileList;
var dp:Array;
var frl:FileReferenceList = new FileReferenceList;
var images_filter:FileFilter = new FileFilter("*.jpg, *.jpeg, *.gif, *.png", "*.jpg;*.jpeg;*.gif;*.png");
var docs_filter:FileFilter = new FileFilter("*.txt, *.doc, *.docx, *.rtf", "*.txt;*.doc;*.docx;*.rtf");
var zip_filter:FileFilter = new FileFilter("*.zip, *.rar", "*.zip;*.rar");
var all_filter:FileFilter=new FileFilter("所有文件 *.*","*.*");
//var header:URLRequestHeader = new URLRequestHeader("pragma", "no-cache");
var uploadURL:URLRequest = new URLRequest(base_url + 'upload.php');
//uploadURL.method = URLRequestMethod.POST;
//uploadURL.requestHeaders.push(header);
public function Upload()
{
////隐藏默认菜单
var contextmenu:ContextMenu = new ContextMenu;
contextmenu.hideBuiltInItems();
////添加右键菜单
var item:ContextMenuItem = new ContextMenuItem('&设计网');
contextmenu.customItems.push(item);
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, function(e:ContextMenuEvent)
{
///URL定向
navigateToURL(new URLRequest(base_url));
});
stage.align = StageAlign.TOP_LEFT;//顶端对齐
stage.scaleMode = StageScaleMode.NO_SCALE;/////缩放模式
addChild(upload_btn);/////
upload_btn.buttonMode = true;
upload_btn.addEventListener(MouseEvent.CLICK, uploadhandler);
frl.addEventListener(Event.SELECT, selectedhandler);
frl.addEventListener(Event.CANCEL, cancelhandler);
stage.addEventListener(Event.RESIZE, resizehandler);
resizehandler(null);
contextMenu = contextmenu;
}
private function resizehandler(e:Event):void
{
////舞台居中
upload_btn.x = Math.floor((stage.stageWidth - upload_btn.width) / 2) + .5;
upload_btn.y = Math.floor((stage.stageHeight - upload_btn.height) / 2) + .5;
}
private function uploadhandler(e:MouseEvent):void
{
frl.browse([images_filter, docs_filter, zip_filter,all_filter]);
}
private function cancelhandler(e:Event):void
{
////
stage.focus = null;
}
private function selectedhandler(e:Event):void
{
removeChild(upload_btn);///删除
upload_details_contain = new TileList;
dp = new Array;
addChild(upload_details_contain);
pending_files_array = new Array();
upload_details_array = new Array();
var fileReferenceList:FileReferenceList = e.target as FileReferenceList;
var fileList:Array = fileReferenceList.fileList;
for (var i:uint = 0; i < fileList.length; i++) {
addPendingFile(fileList[i]);
}
}
private function addPendingFile(file:FileReference):void
{
pending_files_array.push(file);
////上传进度条
var udi:UploadDetailInfo = new UploadDetailInfo;
upload_details_array.push(udi);
dp.push({source:udi});
upload_details_contain.dataProvider = new DataProvider(dp);
upload_details_contain.direction = ScrollBarDirection.VERTICAL;////垂直方向显示游
upload_details_contain.setStyle("contentPadding", 5);
upload_details_contain.columnWidth = udi.width;
upload_details_contain.rowHeight = udi.height + 20;
upload_details_contain.setSize(udi.width, stage.stageHeight);
if(dp.length * upload_details_contain.rowHeight < upload_details_contain.height){
upload_details_contain.setSize(udi.width, dp.length * upload_details_contain.rowHeight);
}
upload_details_contain.move((stage.stageWidth - upload_details_contain.width) / 2, (stage.stageHeight - upload_details_contain.height) / 2);
file.addEventListener(Event.OPEN, openHandler);
file.addEventListener(Event.COMPLETE, completeHandler);
file.addEventListener(ProgressEvent.PROGRESS, progressHandler);
file.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
file.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
file.upload(uploadURL,"Filedata");
}
private function getIndex(file:FileReference):int
{
//////
////多个文件名列表
////返回文件数
for (var i:int; i < pending_files_array.length; i++) {
if (pending_files_array[i].name == file.name) {
return i;
}
}
return i;
}
//////当上传完毕时,清空相关内容
private function removePendingFile(file:FileReference):void
{
for (var i:uint; i < pending_files_array.length; i++) {
if (pending_files_array[i].name == file.name) {
pending_files_array.splice(i, 1);
upload_details_array.splice(i, 1);
if (pending_files_array.length == 0) {
doOnComplete();
}
return;
}
}
}
private function doOnComplete():void
{
/////
removeChild(upload_details_contain);
////保存文件列表
var dp:DataProvider = new DataProvider;
///FRL,fileReferenceList
for(var i=0; i < frl.fileList.length; i++){
var n:String = FileReference(frl.fileList[i]).name;///对于每一个文件的文件名
var l:String = base_url + 'uploads/' + n;
/////对应文件名,上传服务器路径
dp.addItem({label: n, data:l});
}
/////
var list:List = new List;
list.dataProvider = dp;
//居中
list.setSize(stage.stageWidth, stage.stageHeight);
//数组长度*行高
if(dp.length * list.rowHeight < list.height){
list.setSize(stage.stageWidth, dp.length * list.rowHeight);
}
///居中
list.move((stage.stageWidth - list.width) / 2, (stage.stageHeight - list.height) / 2);
addChild(list);
list.addEventListener(Event.CHANGE, handler);
function handler(e:Event):void
{
var dl:FileReference = new FileReference;
downloadFile();
///下载文件
function downloadFile():void
{
dl.download(new URLRequest(list.selectedItem.data));
}
}
///定义文本格式
var tf:TextFormat = new TextFormat;
tf.size = 12;
var success:TextField = new TextField;
success.height = 1;
success.border=true;
success.backgroundColor=0xcccccc;
success.autoSize = TextFieldAutoSize.LEFT;
success.text = '我还要传';
success.textColor = 0xffffff;
success.setTextFormat(tf);
success.x = 0;
success.y = 0;
success.selectable = false;
success.addEventListener(MouseEvent.CLICK, clickhandler);
addChild(success);
///重新上传
function clickhandler(e:MouseEvent):void
{
removeChild(list);
removeChild(e.target as TextField);
addChild(upload_btn);
}
}
private function openHandler(event:Event):void
{
//开始上传
var file:FileReference = FileReference(event.target);
UploadDetailInfo(upload_details_array[getIndex(file)]).ready(file.name);
}
private function completeHandler(event:Event):void
{
////上传完成
var file:FileReference = FileReference(event.target);
UploadDetailInfo(upload_details_array[getIndex(file)]).complete(file.name);
removePendingFile(file);
}
private function progressHandler(event:ProgressEvent):void
{
////上传进度
var file:FileReference = FileReference(event.target);
////还少于10%时
if(event.bytesLoaded / event.bytesTotal < .1){
UploadDetailInfo(upload_details_array[getIndex(file)]).ready(file.name);
} else {
//显示进度
UploadDetailInfo(upload_details_array[getIndex(file)]).updateinfo(file.name, event.bytesLoaded, event.bytesTotal);
}
}
private function ioErrorHandler(event:Event):void
{
///IOERROR处理
}
private function securityErrorHandler(event:Event):void
{
///////
}
}
}
upload.php
<?php
$uploaddir = './uploads/';
$filename = $_FILES['Filedata']['name'];
$tmpname=$_FILES['Filedata']['tmp_name'];
$fp=fopen("myfile.txt","w+");
fwrite($fp,$filename);
fwrite($fp,$tmpname);
fclose($fp);
$uploadfile = $uploaddir . $filename;
$uploadfile = iconv('utf-8', 'gb2312', $uploadfile);
move_uploaded_file($tmpname, $uploadfile);
?>
uploaddetaildata.as
package
{
import flash.display.*;
import flash.text.*;
public class UploadDetailInfo extends Sprite
{
public function UploadDetailInfo()
{
///////
_txt.autoSize = TextFieldAutoSize.LEFT;
_mc.scaleX = 0;
///设置遮罩
_mc.mask = _mask;
}
public function ready(n):void
{
/////准备上传文件名
_txt.text = '准备上传:' + n;
_txt.textColor = 0x666666;
}
public function updateinfo(n,b,t):void
{
///上传进度(总字节,上传字节,文件名)
_txt.text = '正在上传:' + n;
_txt.textColor = 0xff6600;
_mc.scaleX = b/t;
}
public function complete(n):void
{
_txt.text = '上传完成:' + n;
_txt.textColor = 0x0066cc;
_mask.stop();
}
}
}
相关推荐
socket实现的文件上传,带上传的进度条。只是as客户端代码,不包括服务端文件接受处理代码。
本文实例讲述了C#实现HTTP上传文件的方法。分享给大家供大家参考。具体实现方法如下: 发送文件代码如下: 代码如下: /// /// Http上传文件 /// public static string HttpUploadFile(string url, string ...
详细的as3开发,文件的上传,并且带进度条。
用AS3编写,点击不同的按钮加载不同的外部SWF文件,显示在固定尺寸的舞台上,同一时该只能加载一个外部文件,自动调整被加载文件的尺寸以适应容器大小。昨天上传那个不知道为什么见不到,再次上传并添加了部分容错...
通过Flex+ASP.NET实现从HTTP通道上传文件
控件UpdloadFile文件上传eg: string newfilename = file_uploadid.FileName; string size = file_uploadid.PostedFile.ContentLength.ToString(); string type = file_uploadid.PostedFile.ContentType; string ...
flash flex actionscript as3 多文件上传组件
Flash+asp批量上传文件: Flash AS3 + ASP批量上传文件,使用了化境无组件上传类. 需要浏览器安装Flash Player 9.0以上. Flash端用的Flash CS3开发.
使用base64进行文件上传的具体流程是:前台使用js将文件转换为base64格式,后台通过高级编程语言,将base64格式的文件,转换为原文件。下面就来演示一下,C#语言配合js,如何实现图片的base64格式上传与解析保存。...
项目中经常用到需要上传文件、照片等功能,同时需要限制所上传文件的大小。很多插件都会采用后台请求验证,前端Js校验比较少。本篇介绍一个前端JS便捷判断上传文件大小的方法。 这个是比较好的 <html> <...
动态实现多文件上传,基于flex技术,可以动态监控上传进度。
// 3:设置允许上传文件的大小 .这里是3m su.setMaxFileSize(3 * 1024 * 1024); // 4:初始化,接受页面传递过来的请求 su.initialize(getServletConfig(), request, response); // 5:上传 su....
JPGLoader.as ---------------------- 本地图片上传保存 JPGEncoder.as ---------------------- 压缩为jpg PNGEncoder.as ---------------------- 压缩为png component: --button: BasicButton.as ---------...
上传文件 </head> 上传"> </form></td> if(null != request.getParameter("flag")){ SmartUpload mySmartUpload =new SmartUpload(); long file_size_max=4000000; String fileName2="",ext="",testvar=...
json = "{\"statusCode\":\"300\",\"message\":\"上传的文件超过了3000M,请重新选择\",\"navTabId\":\"nav6\",\"rel\":\"\",\"callbackType\":\"\",\"forwardUrl\":\"\"}"; return json; } } } } catch ...
as3 fzip类 解析上传zip文件 因为用到其他项目中。包路径没修改,自己修改下即可使用 ZipEG\ ChecksumUtil.as FZip.as FZipErrorEvent.as FZipEvent.as FZipFile.as FZipLibrary.as
上传文件" OnClick="Button1_Click" /> <asp:Label ID="Label1" runat="server" Height="269px" Text="Label" Width="360px"></asp:Label> cs文件 if (FileUpload1.HasFile) { try { FileUpload1....
给予STC15系列单片机,详细介绍了AS608数据包传送的方式,包括包头包尾的检测与去除,以及完整工程源代码实现,除此之外还还有LCD驱动,双串口运用
FLASH+ASP 文件上传事例 源代码
文件上传下载及消息传输,...有的手机浏览器有权限设置问题,如小米浏览器上传文件不成功,uc浏览器可以 部署在tomcat webapps目录下,mavent生成的war包请改名为upload.war(与html里的上传请求路径有关) 上传请求 ...