zoukankan      html  css  js  c++  java
  • SwfUpload的使用

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-cn" lang="zh-cn">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="Content-Language" content="utf-8" />
    <meta name="robots" content="all" />
    <meta name="author" content="Tencent-ISRD" />
    <meta name="Copyright" content="Tencent" />
    <meta name="Description" content="Qzone精彩由你而来" />
    <meta name="Keywords" content="Qzone,QQ空间,Blog,博客,网络日志,播客,腾讯,QQ,Tencent" />
    <title> </title>
    <style>
    .author-display {display:none;}
    .visitor-display {display:none;}
    </style>
    <link rel="stylesheet" rev="stylesheet" href="upload_photo.css" type="text/css" media="screen"/>
    <link rel="Shortcut Icon" href="/favicon.ico" type="image/x-icon" />
    <style type="text/css">
    <!--
    body {
    /*overflow:hidden;*/
    background-color:transparent;
    }
    -->
    </style>
    <script src="http://imgcache.qq.com/qzone/client/photo/pages/qzone_v4/script/qzflsmall.js"> </script>
    <script src="http://imgcache.qq.com/qzone/client/photo/pages/qzone_v4/script/album.js"> </script>
    <script language="vbscript" src="http://imgcache.qq.com/qzone/client/photo/script/code_proc.vbs"> </script>
    <script src="../js/swfupload.js""> </script>
    </head>
    <body>
    <div class="photo">
        <div class="bg_mode">
          <div class="box_ml bor">
            <div class="mode_gb">
              <!--==S 模块标题-->
              <div class="mode_gb_title style_mode_gb_title" style="height:auto">
              </div>
              <!--==E 模块标题-->
              <!--==S 模框内容-->
              <div class="mode_gb_cont">
    <!--==S 导航指引标题-->
    <!--==E 导航指引标题-->
    <!--==S 相册-->
    <div class="upload_main">
    <div class="upload_main_frame">
    <div class="flash_upload_frame">
    <div class="upload_frame_title">
    <button id="cancel_btn" class="cancel_button" onclick="Flash.cancel()">全部删除 </button>
    <%-- <button class="add_button" id="add_file_btn" onclick="Flash.selectFiles()">添加照片 </button>--%>
    <div id="add_file_btn" style="float:left;padding:6px 2px 0 4px; 63px" > </div>
    <button class="upload_button" id="start_up_btn" onclick="Flash.startUpload()" style="display:none">开始上传 </button>
    <button class="disabled" id="nstart_up_btn" disabled="disabled">开始上传 </button>
    </div>
    <div class="flash_upload_point" id="add_lable">请添加要上传的照片,点击开始上传(可按住ctrl键一次选中15张照片同时添加) </div>
    <div class="flash_upload_point" id="list_lable"  style="display:none"> </div>
    <div class="flash_upload_hint" id="uped_lable"  style="display:none"> </div>
    <div class="flash_upload_main">
    <p class="add_photo_upload" id="add_file"> <a href="javascript:Flash.selectFiles()">添加照片 </a> </p>
    <div id="up_file_title" class="up_file_title" style="display:none">
    <table>
    <colgroup>
    <col style="50%;" />
    <col style="40%;" />
    <col style="10%;" />
    </colgroup>
    <thead>
    <tr>
    <th>名称 </th>
    <th>状态 </th>
    <th style="text-indent:4px;">操作 </th>
    </tr>
    </thead>
    </table>
    </div>
    <div id="up_file_list" class="flash_upload_list" style="display:none"> </div>
    </div>
    </div>

    </div>
    </div>
    <!--==E 相册-->
      </div>
              <!--==E 模框内容-->
            </div>
          </div>
        </div>
    </div>
    </body>

    <script>
    var Flash = (function(){
    var _swfu;
    var _fileArray = [];
    var uploadStatus = 1; //0:可以上传 1:暂停上传,可以继续 -1:停止上传,不可继续 2:中间等待状态
    var inner;
    function showOrHideDel(type){
    var eles = QZONE.dom.getByName("del_up_file","td");
    if(type == "show"){
    for(var i=0; i <eles.length; i++){
    eles[i].style.visibility="";
    }
    }else{
    for(var i=0; i <eles.length; i++){
    eles[i].style.visibility="hidden";
    }
    }
    }
    function getFileIndexById(fid){
    for(var i=0; i < _fileArray.length; i++){
    if(_fileArray[i].id == fid){
    return i;
    }
    }
    }
    function addFile(file){
    for(var i=0; i <_fileArray.length; i++){
    if(file.name==_fileArray[i].name &&
    file.size==_fileArray[i].size &&
    file.creationdate.getTime()==_fileArray[i].creationdate.getTime() &&
    file.modificationdate.getTime()==_fileArray[i].modificationdate.getTime()){
    _swfu.cancelUpload(file.id);
    return false;
    }
    }
    _fileArray.push(file);
    return true;
    }
    function setFileStatus(fid,status){
    _fileArray[getFileIndexById(fid)].filestatus = status;
    }
    //支持 file object 和 status number
    function fileStatus(o){
    var html,status;
    if(typeof(o) == "object" && o.id){
    status = o.filestatus;
    }else{
    status = o;
    }
    switch(status){
    case -1 : html = '等待上传';break;
    case -2 : html = ' <div class="loading_rate"> <div class="rate_bar" style="1%"> </div> </div> <strong class="proportion">1% </strong>';break;
    case -3 : html = '上传失败';break;
    case -4 : html = '上传成功!';break;
    case -5 : html = '取消上传';break;
    case -6 : html = ' <span class="loading_hint">照片大小超过2M </span>';break;
    //自己定义的错误吗
    case -501 : html = ' <span class="loading_hint">对不起,服务器忙! </span>';break;
    case -502 : html = ' <span class="loading_hint">文件出错! </span>';break;
    case -503 : html = "上传成功!";break;
    case -504 : html = "上传失败";break;
    case -505 : html = "上传失败";break;
    case -506 : html = ' <span class="loading_hint">照片大小超过2M </span>';break;
    case -507 : html = ' <span class="loading_hint">文件大小为0 </span>';break;
    case -508 : html = ' <span class="loading_hint">文件格式错误 </span>';break;
    case -509 : html = ' <span class="loading_hint">登陆超时 </span>';break;
    case -510 : html = ' <span class="loading_hint">含有违规信息! </span>';break;
    }
    return html;
    }
    function buildHtml(){
    var html=[];
    var size = 0, count, errCount = 0;
    if(_fileArray.length < 1){
    $hide("up_file_list");
    $hide("up_file_title");
    $show("add_file");

    $hide("list_lable");
    $hide("uped_lable");
    $show("add_lable");

    $hide("start_up_btn");
    $show("nstart_up_btn");
    $("cancel_btn").disabled = true;
    return;
    }else{
    $show("up_file_list");
    $show("up_file_title");
    $hide("add_file");

    $hide("add_lable");
    $show("list_lable");
    $show("uped_lable");

    $show("start_up_btn");
    $hide("nstart_up_btn");
    $("cancel_btn").disabled = false;
    }
    for(var i = 0; i < _fileArray.length; i++){
    var name = _fileArray[i].name.replace(/\.[a-zA-Z]+$/g,"");
    if(name.lenB() > 14){
    name = name.leftB(14) + "...";
    }
    var tmp = [
    ' <tr>',
    ' <td>'+name+' </td>',
    ' <td id="page_'+_fileArray[i].id+'">',
    fileStatus(_fileArray[i]),
    ' </td>',
    ' <td name="del_up_file"> <button title="删除" class="icon_photo_delete" onclick="Flash.delFile(\''+_fileArray[i].id+'\')"> <span>删除 </span> </td>',
    ' </tr>'
    ].join("");
    html.push(tmp);
    if(_fileArray[i].size == null || typeof(_fileArray[i].size) != "number"){
    _fileArray[i].size = 0;
    }
    size += _fileArray[i].size;
    if(_fileArray[i].filestatus == -6 || _fileArray[i].filestatus == -506){
    errCount++;
    }
    }
    if(size > 1024 * 1024){
    size = "(大小"+Math.round((size/1024/1024)*100)/100+"MB)";
    }else if(size > 1024){
    size = "(大小"+parseInt(size/1024)+"KB)";
    }else{
    size = "(大小"+parseInt(size)+"B)";
    }
    count = " <strong>"+_fileArray.length+" </strong>"
    if(errCount > 0){
    $("uped_lable").innerHTML = '已添加'+count+'张照片'+size+" "+errCount+'张照片大小超过2M,请使用 <a href="javascript:Page.goActUp()" style="color:#EA0000">极速上传工具 </a>上传';
    $hide("list_lable");
    }else{
    $("list_lable").innerHTML = '已添加'+count+'张照片'+size;
    $hide("uped_lable");
    }
    $("up_file_list").innerHTML = [
    ' <table>',
    ' <colgroup>',
    ' <col style="50%;" />',
    ' <col style="40%;" />',
    ' <col style="10%;" />',
    ' </colgroup>',
    ' <tbody>',
    html.join(""),
    ' </tbody>',
    ' </table>'
    ].join("");
    }
    return inner = {
    init : function(upurl){
    var settings = {
    flash_url : "swfupload_f9.swf",
    flash_width : "63px",
    flash_height : "25px",
    flash_container_id : "add_file_btn",
    upload_url: upurl,
    file_post_name : "filename",
    post_params: {
    "tagtext" : "",
    "refer" : "qzone",
    "output_type" : "json",
    "callback_fuc" : "upload"
    },
    file_size_limit : "2MB",
    file_types : "*.jpg;*.gif;*.jpeg;*.png",
    file_types_description : "图片",
    file_upload_limit : 15,
    file_queue_limit : 0,
    custom_settings : {},
    debug: false,
    // The event handler functions are defined in handlers.js
    swfupload_loaded_handler : Flash.flashReady,
    file_queued_handler : Flash.fileQueued,
    file_queue_error_handler : Flash.fileQueueError,
    file_dialog_complete_handler : Flash.fileDialogComplete,
    upload_start_handler : Flash.uploadStart,
    upload_progress_handler : Flash.uploadProgress,
    upload_error_handler : Flash.uploadError,
    upload_success_handler : Flash.uploadSuccess,
    upload_complete_handler : Flash.uploadComplete,
    queue_complete_handler : Flash.queueComplete // Queue plugin event
    };
    if(_swfu){
    _swfu.destroy();
    }
    _swfu = new SWFUpload(settings);
    _fileArray = [];
    uploadStatus = 1;
    $("cancel_btn").innerHTML = "全部删除";
    $("start_up_btn").innerHTML = "开始上传"
    $("add_file_btn").disabled = true;
    $("add_file").disabled = true;
    buildHtml();
    },
    addPostParam : function(name,value){
    try{
    _swfu.addPostParam(name,value);
    }catch(e){};
    },
    selectFiles : function(){
    try{
    _swfu.selectFiles();
    }catch(e){};
    },
    startUpload : function(){
    if(!Page.checkAid()) return;
    if(uploadStatus != -1){
    if(!(parent.checkLogin()>10000)){
    LoginBack = function(){
    Flash.startUpload();
    }
    parent.showLoginBox("photo");
    return;
    }else if(User.isOwner()){//只有主人才可以上传
    _swfu.startUpload();

    }else{
    alert("您输入的相册主人ID不对!");
    qz_go_imc("album_list.htm");
    }
    }
    },
    delFile : function(fid){
    var tmp = [];
    for(var i = 0; i < _fileArray.length; i++){
    if(fid != _fileArray[i].id){
    tmp.push(_fileArray[i]);
    }
    }
    _fileArray = tmp;
    _swfu.cancelUpload(fid);
    buildHtml();
    },
    setUploadStatus : function(status){
    status = parseInt(status);
    if(status < -1 || status > 1) return;
    uploadStatus = status;//0:可以上传 1:暂停上传,可以继续 -1:停止上传,不可继续
    showOrHideDel("show");
    },
    getStats : function(){
    stats = _swfu.getStats();
    var suc = 0; err = 0;
    for(var i=0; i < _fileArray.length; i++){
    if(_fileArray[i].filestatus == -4 || _fileArray[i].filestatus == -503){
    suc++;
    }else{
    err++;
    }
    }
    stats.real_success = suc;
    stats.real_error = err;
    stats.real_total = suc + err;
    return stats;
    },
    clean : function(){
    for(var i=0; i < _fileArray.length; i++){
    _swfu.cancelUpload(_fileArray[i].id);
    }
    _fileArray = [];
    uploadStatus = 1;
    buildHtml();
    },
    cancel : function(){
    if(uploadStatus == 0){
    Flash.setUploadStatus(1);
    $("cancel_btn").innerHTML = "全部删除";
    $("start_up_btn").innerHTML = "重新上传"
    }else{
    Flash.clean();
    }
    },

  • 相关阅读:
    asp.net 网页标题、关键字、描述
    星级评分jQuery插件
    以jquery为基础的星星评分
    投票系统显示结果jQuery插件
    JAVASCRIPT模拟模式对话窗口
    Repeater 嵌套代码
    window服务程序安装卸载批处理文件
    c#window程序开发入门系列自学笔记
    jquery 模式对话框改进版
    php的正则表达式完全手册
  • 原文地址:https://www.cnblogs.com/juan/p/1441469.html
Copyright © 2011-2022 走看看