87,922
社区成员
发帖
与我相关
我的任务
分享
这个好像就规定了文件的类型和大小啊,我做的demo跟这个差不多,可以上传。但是我把代码搬到别的页面里的时候就传不了,主要是调试的时候都没有运行到UploadHandler.ashx c#一窍不通,参考一下这个地址:http://blog.csdn.net/smartsmile2012/article/details/8489870
c#一窍不通,参考一下这个地址:http://blog.csdn.net/smartsmile2012/article/details/8489870
我下uploadify,发现没配置文件,是在UploadHandler.ashx中判断文件类型。贴一下你的UploadHandler.ashx吧
using System;
using System.Web;
using System.IO;
using System.Linq;
using System.Collections.Generic;
public class UploadHandler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
context.Response.Charset = "utf-8";
HttpPostedFile file = context.Request.Files["Filedata"];
string uploadPath =
HttpContext.Current.Server.MapPath(@context.Request["folder"]) + "\\";
if (file != null)
{
if (!Directory.Exists(uploadPath))
{
Directory.CreateDirectory(uploadPath);
}
string time = DateTime.Now.ToString("yyyyMMddhhmmss");
file.SaveAs(uploadPath +time+ file.FileName);
//下面这句代码缺少的话,上传成功后上传队列的显示不会自动消失
context.Response.Write("1");
}
else
{
context.Response.Write("0");
}
}
public bool IsReusable {
get {
return false;
}
}
}
代码应该没问题,我单独做了一个demo,可以运行,没问题。这是从demo那copy过来的,调试的时候都没有运行到ashx文件贴一下你的uploadify配置文件 txt应该可以把,word文档也不行 你上传文件的类型是uploadify设置允许的类型吗
txt应该可以把,word文档也不行 你上传文件的类型是uploadify设置允许的类型吗
你上传文件的类型是uploadify设置允许的类型吗
上上代代码码
<a href="###" class="btn" id="upload" style="float: none; display: inline-block;margin: 0px;">上传附件</a>
<input type="hidden" name="wholedir" value="" class="wholedir" />
<span class="filelist"></span>
var uploadBind = function () {
$('#upload').unbind('click').bind('click', function () {
var html = '<div id="filepart" class="alerter_oneL"><div class="alerter_input1">文件上传:<input type="file" id="fileupload" /></div><div id="filequeue"></div><div class="alerter_btn"><a href="###" id="startUploadLink">上传</a><a href="###" id="clearQueueLink">取消</a></div></div>';
ocean.alerter_on(html, 'alerter3', 'body');
if ($("#fileuploadUploader").length != 0) {
$("#fileupload").remove();
$("#fileuploadUploader").remove();
$('#filequeue').before('<input type="file" id="fileupload" />');
$("#startUploadLink").remove();
$('#filequeue').after('<a href="###" id="startUploadLink">上传</a>');
$('#filequeue').empty();
$("#clearQueueLink").remove();
$("#startUploadLink").after('<a href="###" id="clearQueueLink">取消</a>');
}
// var uploadfolderid = AjaxServer.Ajax.GetUploadFolder(1449).value;
$("#fileupload").uploadify({
'uploader': 'uploadify/uploadify.swf',
'script': 'UploadHandler.ashx',
'cancelImg': 'uploadify/cancel.png',
'folder': 'UploadFile',
// 'scriptData': { 'folderID': uploadfolderid, 'note': '', 'userName': userName, 'userName_EncryptCookie': userName_EncryptCookie, 'userID': userID },
'multi': true,
'auto': false,
'queueID': 'filequeue',
'onAllComplete': function (event, data) {
$("#fileuploadUploader").css("visibility", "inherit");
$("#filepart").hide();
if (errormsg.length > 0) {
ocean.errorAlerter(errormsg);
}
else {
var msg = '';
if (data.errors > 0) {
msg = "<p>共上传文件" + data.filesUploaded + "个," + data.errors + "个失败</p>";
}
else {
msg = "<p>上传成功</p>"
}
ocean.alerter_off();
ocean.errorAlerter(msg);
}
showfilelist();
},
'onComplete': function (event, queueId, fileObj, response, data) {
if (response.indexOf('Error') > -1) {
errormsg += response;
}
else {
fileidlist += response + ',';
}
}
});
$("#startUploadLink").click(function () {
$("#fileupload").uploadifyUpload();
});
$("#clearQueueLink").click(function () {
$("#fileupload").uploadifyClearQueue();
ocean.alerter_off();
});
})
}
ashx文件应该没问题你贴的图不像是错误提示