首页 新闻 会员 周边

jquery的Uploadify上传图片的问题!!求指教!!

0
悬赏园豆:10 [已关闭问题] 关闭于 2014-04-16 09:08

1.Default.aspx页面

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>PictureUpload</title>
    <link href="Scripts/uploadify.css" rel="stylesheet" type="text/css" />
    <script src="Scripts/jquery-1.9.1.js" type="text/javascript"></script>
    <script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <script src="Scripts/jquery.uploadify.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $("#uploadify").uploadify({
                //指定swf文件
                'swf': 'Scripts/uploadify.swf',
                //后台处理的页面
                'uploader': 'UploadHandler.ashx',
                //按钮显示的文字
                'buttonText': '上传图片',
                //显示的高度和宽度,默认 height 30;width 120
                'height': 15,
                'width': 80,
                'folder': 'UploadFile', //上传文件夹名
                //上传文件的类型  默认为所有文件    'All Files'  ;  '*.*'
                //在浏览窗口底部的文件类型下拉菜单中显示的文本
                'fileTypeDesc': 'Image Files',
                //允许上传的文件后缀
                'fileTypeExts': '*.gif; *.jpg; *.png',
                //发送给后台的其他参数通过formData指定
                'formData': { 'someKey': 'someValue', 'someOtherKey': 1 },
                //上传文件页面中,你想要用来作为文件队列的元素的id, 默认为false  自动生成,  不带#
                'queueID': 'fileQueue',
                //选择文件后自动上传
                'auto': false,
                //设置为true将允许多文件上传
                'multi': true
            });
        });
    </script>
</head>
<body>
    <div>
        <%--用来作为文件队列区域--%>
        <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>
    </div>
</body>
</html>

2.ashx文件

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

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

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            //http://www.cnblogs.com/babycool/
            //接收上传后的文件
            HttpPostedFile file = context.Request.Files["Filedata"];
            //其他参数
            //string somekey = context.Request["someKey"];
            //string other = context.Request["someOtherKey"];
            //string folder = context.Request["folder"];
            //获取文件的保存路径
            string uploadPath =
                HttpContext.Current.Server.MapPath(context.Request["folder"] + "\\");
            //判断上传的文件是否为空
            if (file != null)
            {
                if (!Directory.Exists(uploadPath))
                {
                    Directory.CreateDirectory(uploadPath);
                }
                //保存文件
                file.SaveAs(uploadPath + file.FileName);
                context.Response.Write("1");
            }
            else
            {
                context.Response.Write("0");
            }

        }

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

问题:图片能够上传,但是保存不到UploadFile文件夹里面,设断点看到图片也取到了!!求教各位老大们指教!!非常感谢!!

Akon_Coder的主页 Akon_Coder | 初学一级 | 园豆:134
提问于:2014-04-15 14:44
< >
分享
所有回答(3)
0

没有权限写硬盘。看看是那个账号在跑网站,让后给UploadFile加上写的权限

arg | 园豆:1047 (小虾三级) | 2014-04-15 14:48
0

图片存储在什么位置,完全取决于接收。

建议不要使用folder这个参数,可以使用formData代替。

lucika.zh | 园豆:62 (初学一级) | 2014-04-15 14:48
0

从代码看没有什么问题,在Path处加个断点看看目录创建情况。顺便说下,Folder这个参数应该就是后台设定的,交给前台是个错误的决定。

happydaily | 园豆:301 (菜鸟二级) | 2014-04-15 16:18
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册