首页 > 其他分享 >uploadify上传控件

uploadify上传控件

时间:2022-12-01 15:31:40浏览次数:64  
标签:控件 file 文件 uploadify System context 上传


下载控件:uploadify 分为2种,选择Flash Version版本

地址:​​http://www.uploadify.com/​​ 

页面代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Upload.aspx.cs" Inherits="Hot.Upload" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link href="Scripts/upload/uploadify.css" rel="stylesheet" />
<script src="Scripts/jquery-1.7.1.min.js"></script>
<script src="Scripts/upload/jquery.uploadify.min.js"></script>
<title>上传控件</title>

<script type="text/javascript">
$(document).ready(function () {
$("#uploadify").uploadify({
'swf': 'Scripts/upload/uploadify.swf',
'uploader': '/UploadHandler.ashx',
'cancelImg': 'Scripts/upload/uploadify-cancel.png',
'queueID': 'fileQueue',
'uploadLimit': 1000, //一次浏览器课上成总数量
//'fileSizeLimit': '100MB', //单个文件大小设置
'auto': false,
'multi': true,
'onFallback':function(){
alert("您未安装FLASH控件,无法上传图片!请安装FLASH控件后再试。");
},
//返回一个错误,选择文件的时候触发
'onSelectError': function (file, errorCode, errorMsg) {
switch (errorCode) {
case -100:
alert("上传的文件数量已经超出系统限制的" + $('#file_upload').uploadify('settings', 'queueSizeLimit') + "个文件!");
break;
case -110:
alert("文件 [" + file.name + "] 大小超出系统限制的" + $('#file_upload').uploadify('settings', 'fileSizeLimit') + "大小!");
break;
case -120:
alert("文件 [" + file.name + "] 大小异常!");
break;
case -130:
alert("文件 [" + file.name + "] 类型不正确!");
break;
}
alert(errorCode);
},
'onUploadStart': function (file) {
},
'onUploadSuccess': function (file, data, response) {
$('#' + file.id).find('.data').html(' 上传完毕');
},
'onUploadComplete': function () {

}

});
});
</script>

</head>
<body>

<div id="fileQueue"></div>
<input type="file" name="uploadify" id="uploadify" />
<p>
<a href="javascript:$('#uploadify').uploadify('upload','*')">上传</a>|
<a href="javascript:$('#uploadify').uploadify('cancel', '*')">取消上传</a>
</p>


</body>
</html>

上传到后台:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;

namespace Hot
{
/// <summary>
/// UploadHandler 的摘要说明
/// </summary>
public class UploadHandler : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";

//接收上传后的文件
HttpPostedFile file = context.Request.Files["Filedata"];
//其他参数
//string somekey = context.Request["someKey"];
//string other = context.Request["someOtherKey"];
//获取文件的保存路径 创建uploads文件夹
string uploadPath =HttpContext.Current.Server.MapPath("uploads" + "\\");
//判断上传的文件是否为空
if (file != null)
{
if (!Directory.Exists(uploadPath))
{
Directory.CreateDirectory(uploadPath);
}
//1.利用InputStream 属性直接从HttpPostedFile对象读取文本内容
System.IO.Stream MyStream;
int FileLen;
FileLen = file.ContentLength;
// 读取文件的 byte[]
byte[] bytes = new byte[FileLen];
MyStream = file.InputStream;
MyStream.Read(bytes, 0, FileLen);

//2.保存到文件
file.SaveAs(uploadPath + file.FileName);
context.Response.Write("1");
}
else
{
context.Response.Write("0");
}

}

public bool IsReusable
{
get
{
return false;
}
}
}
}

1.记得创建uploads文件夹,放上传的文件。

 2.$('#' + file.id).find('.data').html(' 上传完毕'); 是设置显示为中文完成,不然是英文,也可以更改jquery.uploadify.js文件里的英文字。

标签:控件,file,文件,uploadify,System,context,上传
From: https://blog.51cto.com/u_15898776/5902201

相关文章

  • 使用 FormData上传file文件 使用接口通过FormData上传头像
    文件选择标签type="file"属性可以获取选择文件accept="image/*"推荐选择图片类/*通配,所有placeholder提示信息语法:1.`accept`属性引导用户选择文件1.多个......
  • layui upload 分块上传实现
    由于项目需要上传超大文件,当然现在的条件好了,1-3百M的文件没多大问题,但是超过1G的还是有问题的。(当然oss单个文件最高可以5g)对于大额文件上传存在上传缓慢甚至失败的问题......
  • iOS开发之打包上传到App Store——(一)各种证书的理解
     OK,有日子没写iOS开发的相关文章啦,主要是最近的精力都没在这上面,不过既然产品已经快要出来了,就有必要了解一下各种证书啥的(众所周知iOS的一堆证书可是很让人头大呀),最近......
  • MFC--List列表控件
           ......
  • PHP上传进度条深度解析
    分析一、程序需要php的apc模块的支持,关键点就是在上传的form里添加一个hidden的inpu标签,里面要有name为APC_UPLOAD_PROGRESS的属性,value值为一个随机数一遍多个人上传。apc......
  • PHP 大文件上传进度条实现
    核心提示:目前我知道的方法有两种,一种是使用PHP的创始人RasmusLerdorf写的APC扩展模块来实现,另外一种方法是使用PECL扩展模块uploadprogress实现。目前我知道的方法有两种......
  • UISegmentedControl分段控件使用
    UISegmentedControl分段控件代替了桌面OS上的单选按钮。不过它的选项个数非常有限,因为你的IOS设备屏幕有限。当我们需要使用选项非常少的单选按钮时它很合适。这个控件的可......
  • minio上传文件
    1.pomminio依赖2.application.yml中添加minio参数3.config下读取yml中的minio配置信息importlombok.Data;importorg.springframework.boot.context.properties.Config......
  • 从零开始的docker和docker-compose打包上传自己的镜像
    步骤:项目准备1.下载一个干净的springboot项目,没有多余的依赖​​https://github.com/wangzixi-diablo/mySpringBoot​​2.进入项目文件夹,运行mvnspring-boot:run查看运行结......
  • vue a-upload组件上传图片,headers和data字段自定义
    <divclass="clearfix"><a-uploadlist-type="picture-card":file-list="fileList"@preview="handlePreview"@change="handleChange":before-upload="......