当前位置:编程学习 > C#/ASP.NET >>

jQuery实现文件上传功能

不能用控件,就是用jQuery代码实现的,就是单击上传按钮,如果上传成功之后,把文件的路径保存在一个文本框里,并且有上传成功的提示信息,亲,怎么实现的啊,如果有相关的插件和怎么用的,可以发在我的邮件,谢谢啊 ,很急的,215704087@qq.com --------------------编程问答-------------------- jQuery有现成的上传插件。。很好用的 --------------------编程问答-------------------- 洗脚,明天发给你 --------------------编程问答-------------------- 想要上传产品图片什么的吧?

平常都是用服务器控件上传文件,web编辑器也能上传,一般来说使用这个web编辑器是在一篇文章里面插入图片,很方便快捷。其实完全可以使用这个web编辑器上传图片转换为你平时上传的产品图片,使用web编辑器一般都是会生成标准的html代码,你可以利用正则表达式将图片路径过滤并且提取出来,保存到你的产品信息里面 --------------------编程问答-------------------- uploadyfiy --------------------编程问答-------------------- http://blog.csdn.net/joyhen/article/details/8290796修改一下就是你要的代码了 --------------------编程问答--------------------
你要的就是这个。
还有配一个ashx文件使用,代码如下
<%@ WebHandler Language="C#" Class="uploadify" %>
using System;
using System.Web;
public class uploadify : IHttpHandler
{
    protected System.Web.UI.HtmlControls.HtmlInputFile filMyFile;
    protected lib.Config configManager;
    
    public void ProcessRequest(HttpContext context)
    {
        configManager = new lib.Config(context.Server.MapPath(VirtualPathUtility.GetDirectory(context.Request.Path)+@"..\..\"));
        
        if (null != context.Request.Files["Filedata"])
        {
            HttpPostedFile myFile = context.Request.Files["Filedata"];
            int nFileLen = myFile.ContentLength;
            byte[] myData = new byte[nFileLen];
            myFile.InputStream.Read(myData, 0, nFileLen);
            System.IO.FileStream newFile = new System.IO.FileStream(configManager.getConfig("path.pdf") + myFile.FileName, System.IO.FileMode.Create);
            newFile.Write(myData, 0, myData.Length);
            newFile.Close();
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
} --------------------编程问答-------------------- <input id="file_upload" type="file" name="Filedata" />
ajax实现的jq代码是:
$(function() {
$('#file_upload').uploadify({
'swf'   : 'admin_files/controls/uploadify.swf',
'uploader'     : 'admin_files/controls/uploadify.ashx',
'cancelImg'  : 'admin_files/images/cancel.png',
'removeCompleted' : true,
'hideButton'  : true,
'auto'  : true,
'queueID'  : 'upload-queue',
'fileTypeDesc'    : 'PDF Files (.PDF)',
'onUploadError' : function(file, errorCode, errorMsg, errorString) {
             $('#permissions_hint').show();
         },
'onQueueComplete' : function(queueData) {
if(queueData.uploadsSuccessful>0){
      window.location.reload(true);
}
     }
    });
}); --------------------编程问答-------------------- 必须的顶啊啊啊啊啊 --------------------编程问答--------------------

<script type="text/javascript" src="scripts/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="scripts/swfobject.js"></script>
<script type="text/javascript" src="scripts/jquery.uploadify.v2.0.2.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#uploadify").uploadify({
            'uploader': 'scripts/uploadify.swf', //上传所需的flash文件
            'script': 'scripts/upload.ashx', //后台处理文件
            'cancelImg': 'cancel.png', //取消按钮的图片
            'buttonImg': 'image/SelectFiles.jpg', //按钮图片
            'folder': '/UploadFile/A', //上传文件夹
            'queueID': 'fileQueue',
            'queueSizeLimit': 4, //限制每次选择文件的个数
            'auto': false, //是否自动上传
            'multi': true, //是否多选
            'sizeLimit': 10737418240, //上传文件限制的最大值
            'simUploadLimit': 1, //同时上传的文件个数
            'fileDesc': '图片文件', //文件类型的描述信息
            'fileExt': '*.jpg;*.png;*.bmp;*.gif;*.*', //设置文件类型
            'onQueueFull': function (event, queueSizeLimit) { alert("只允许上传" + queueSizeLimit + "个文件"); event.data.action(event, queueSizeLimit) = false; },
            'width': 100, //按钮宽度
            'height': 30, //按钮高度
            'wmode': 'transparent', //设置按钮背景透明
            'onAllComplete':
           function (event, queueID, fileObj, response, data) {
               document.getElementById("Button1").click();
               //全部上传完成后的触发的事件,这里你可以写直接弹信息 不一定要像我一样要促发Button 

           }
        });
    });





你只要去下载jquery包就行了,备注很详细了
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,