求jquery神人来指点小弟。急急急急~~~~~~

zl58859173 2013-11-11 07:18:00
项目里面需要用到批量上传的功能,所以选择了用jquery.uploadify。
但是我从网上下载下来的DEMO在本地运行都没问题,但是我把DEMO的代码加入项目中时(代码丝毫未动,只有上传文件夹名称变了),总是报IO ERROR。断点也进不去。网上搜了很久也未发现解决办法。
被这个问题困扰了好几周了,求神人来指点小弟。我怀疑是否是路径问题。


这是DEMO的路径



这是项目中的路径

代码如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="GJProj.Admin.WebForm1" %>

<!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 id="Head1" runat="server">
<title>无标题页</title>
<link href="scripts/uploadify.css" rel="stylesheet" type="text/css" />
<link href="scripts/default.css" rel="stylesheet" type="text/css" />

<script src="scripts/jquery-1.7.2.min.js" type="text/javascript"></script>

<script src="scripts/swfobject.js" type="text/javascript"></script>

<script src="scripts/jquery.uploadify.min.js" type="text/javascript"></script>

<script type="text/javascript">
$(function () {
$("#file_upload").uploadify({
//开启调试
'debug': false,
//是否自动上传
'auto': false,
'buttonText': '选择照片',
//flash
'swf': "scripts/uploadify.swf",
//文件选择后的容器ID
'queueID': 'uploadfileQueue',
'uploader': 'scripts/upload.ashx',
'width': '75',
'height': '24',
'multi': true,
'fileTypeDesc': '支持的格式:',
'fileTypeExts': '*.jpg;*.jpge;*.gif;*.png',
'fileSizeLimit': '10MB',
'queueSizeLimit':'999',
'removeTimeout': '1',

//返回一个错误,选择文件的时候触发
'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;
}
},
//检测FLASH失败调用
'onFallback': function () {
alert("您未安装FLASH控件,无法上传图片!请安装FLASH控件后再试。");
},
//上传到服务器,服务器返回相应信息到data里
'onUploadSuccess': function (file, data, response) {
//alert(data);
}
});
});

function doUplaod() {
$('#file_upload').uploadify('upload', '*');
}

function closeLoad() {
$('#file_upload').uploadify('cancel', '*');
}


</script>

</head>
<body>
<table width="704" border="0" align="center" cellpadding="0" cellspacing="0" id="__01">
<tr>
<td align="center" valign="middle">
<div id="uploadfileQueue" style="padding: 3px;">
</div>
<div id="file_upload">
</div>
</td>
</tr>
<tr>
<td height="50" align="center" valign="middle">
<img alt="" src="img/BeginUpload.gif" width="77" height="23" onclick="doUplaod()" style="cursor: hand" />
<img alt="" src="img/CancelUpload.gif" width="77" height="23" onclick="closeLoad()" style="cursor: hand" />
</td>
</tr>
</table>
</body>
</html>



using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Web.SessionState;
using System.IO;

namespace GJProj.Admin.scripts
{
/// <summary>
/// $codebehindclassname$ 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class upload : IHttpHandler, IRequiresSessionState
{

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

HttpPostedFile file = context.Request.Files["Filedata"];
string uploadPath = context.Server.MapPath("..\\Images\\");

if (file != null)
{
if (!Directory.Exists(uploadPath))
{
Directory.CreateDirectory(uploadPath);
}
file.SaveAs(uploadPath + file.FileName);
//生成缩略图
MakeThumbnail(uploadPath + file.FileName, uploadPath + "\\s\\" + file.FileName, 80, 80);
}
}

private void MakeThumbnail(string sourcePath, string newPath, int width, int height)
{
System.Drawing.Image ig = System.Drawing.Image.FromFile(sourcePath);
int towidth = width;
int toheight = height;
int x = 0;
int y = 0;
int ow = ig.Width;
int oh = ig.Height;
if ((double)ig.Width / (double)ig.Height > (double)towidth / (double)toheight)
{
oh = ig.Height;
ow = ig.Height * towidth / toheight;
y = 0;
x = (ig.Width - ow) / 2;

}
else
{
ow = ig.Width;
oh = ig.Width * height / towidth;
x = 0;
y = (ig.Height - oh) / 2;
}
System.Drawing.Image bitmap = new System.Drawing.Bitmap(towidth, toheight);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.Clear(System.Drawing.Color.Transparent);
g.DrawImage(ig, new System.Drawing.Rectangle(0, 0, towidth, toheight), new System.Drawing.Rectangle(x, y, ow, oh), System.Drawing.GraphicsUnit.Pixel);
try
{
bitmap.Save(newPath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch (Exception ex)
{
throw ex;
}
finally
{
ig.Dispose();
bitmap.Dispose();
g.Dispose();
}

}

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

真心求大神指点。。
...全文
592 35 打赏 收藏 转发到动态 举报
写回复
用AI写文章
35 条回复
切换为时间正序
请发表友善的回复…
发表回复
zl58859173 2013-11-25
  • 打赏
  • 举报
回复
问题已解决,原来我直接从网上拷贝的一般处理文件ashx文件不能直接运用到项目中,我将下载demo中的ashx文件删除,新建一个代码内容一模一样的一般处理文件就可以了,断点也跟进去了。 另外还发现了一个问题,就是模态窗口貌似也不支持这个上传控件,我用window.open()打开的页面就可以了。 感谢各位的出谋划策。
zl58859173 2013-11-13
  • 打赏
  • 举报
回复
引用 28 楼 zxy397472251 的回复:
'fileSizeLimit': '10MB', 应该是 'fileSizeLimit': '2097152', 吧?
不是这个原因呢。
CqCoder 2013-11-13
  • 打赏
  • 举报
回复
'fileSizeLimit': '10MB', 应该是 'fileSizeLimit': '2097152', 吧?
zl58859173 2013-11-13
  • 打赏
  • 举报
回复
引用 26 楼 peng2739956 的回复:
他得默认文件夹的名字你改了么,你改回来能成功吗?
试过了,我用demo的文件夹名也不行。 想死的心都有了。
peng2739956 2013-11-13
  • 打赏
  • 举报
回复
他得默认文件夹的名字你改了么,你改回来能成功吗?
zl58859173 2013-11-13
  • 打赏
  • 举报
回复
又折腾了一天还是没搞定,快疯了。
asd7332371 2013-11-13
  • 打赏
  • 举报
回复
IIS要设置的,http://blog.csdn.net/w3031213101/article/details/6335878
  • 打赏
  • 举报
回复
1:检查命名空间 namespace GJProj.Admin.scripts 你demo拷贝过来 是否和自己项目的命名空间不同,所以断点进不去。 2:检查调用的路径是否正确:'uploader': 'scripts/upload.ashx',
  • 打赏
  • 举报
回复
using System.IO;命名空间
lee_ttxs 2013-11-13
  • 打赏
  • 举报
回复
文件夹属性是可写的吗?这个文件夹有用户权限限制吗?
zl58859173 2013-11-13
  • 打赏
  • 举报
回复
会不会是哪个JS的源文件里面需要修改东西啊?
信不信由你zzy 2013-11-12
  • 打赏
  • 举报
回复
引用 15 楼 zl58859173 的回复:
刚才查了下,发现了一个错误说明。 IO Error : File ID: SWFUpload_0_0. IO Error: Error #2038 不知道是啥意思,有高人指点吗?
我也遇到过这种情况,是配置文件里面的默认上传文件大小不够,好像默认的是3M
zl58859173 2013-11-12
  • 打赏
  • 举报
回复
刚才查了下,发现了一个错误说明。 IO Error : File ID: SWFUpload_0_0. IO Error: Error #2038 不知道是啥意思,有高人指点吗?
ltcszk 2013-11-12
  • 打赏
  • 举报
回复
引用 13 楼 zl58859173 的回复:
[quote=引用 12 楼 ltcszk 的回复:] string uploadPath = context.Server.MapPath("..\\Images\\"); 最好不要用相对与当前文件的路径,你在这句之后断点看看uploadPath 的路径对不对
ashx代码断点压根进不去呢。不然就知道是不是路径的问题了。[/quote] 堆栈显示的是哪里的错误?
zl58859173 2013-11-12
  • 打赏
  • 举报
回复
引用 12 楼 ltcszk 的回复:
string uploadPath = context.Server.MapPath("..\\Images\\"); 最好不要用相对与当前文件的路径,你在这句之后断点看看uploadPath 的路径对不对
ashx代码断点压根进不去呢。不然就知道是不是路径的问题了。
ltcszk 2013-11-12
  • 打赏
  • 举报
回复
string uploadPath = context.Server.MapPath("..\\Images\\"); 最好不要用相对与当前文件的路径,你在这句之后断点看看uploadPath 的路径对不对
Ahoo 2013-11-12
  • 打赏
  • 举报
回复
引用 9 楼 zl58859173 的回复:
[quote=引用 8 楼 tsgx_1989 的回复:] [quote=引用 5 楼 zl58859173 的回复:] [quote=引用 4 楼 tsgx_1989 的回复:] 报错信息具体点。
不好意思,没说清楚。是IO ERROR。 网上查了很多关于这个报错的解决方法,但是都没用。[/quote] 有很多种情况会出现 IO ERROR 具体的报错内容[/quote] 这个看不到啊。要能看到或者跟踪到,应该就能找到解决方法了。[/quote] 浏览器F12 调试,看响应的内容
OSMeteor 2013-11-12
  • 打赏
  • 举报
回复
IO ERROR 应该是路径的错误,你看看执行代码里面的路径,一般会检查是否存在这个路径,不存在就创建,你看看上传的代码。 原因应该是:不存在哪个文件夹,而且应提交成功了。在执行代码里面去找找。。。。
zl58859173 2013-11-12
  • 打赏
  • 举报
回复
引用 8 楼 tsgx_1989 的回复:
[quote=引用 5 楼 zl58859173 的回复:] [quote=引用 4 楼 tsgx_1989 的回复:] 报错信息具体点。
不好意思,没说清楚。是IO ERROR。 网上查了很多关于这个报错的解决方法,但是都没用。[/quote] 有很多种情况会出现 IO ERROR 具体的报错内容[/quote] 这个看不到啊。要能看到或者跟踪到,应该就能找到解决方法了。
Ahoo 2013-11-12
  • 打赏
  • 举报
回复
引用 5 楼 zl58859173 的回复:
[quote=引用 4 楼 tsgx_1989 的回复:] 报错信息具体点。
不好意思,没说清楚。是IO ERROR。 网上查了很多关于这个报错的解决方法,但是都没用。[/quote] 有很多种情况会出现 IO ERROR 具体的报错内容
加载更多回复(15)

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧