偶菜鸟,这几天研究提交上传的问题,弄了几天还是不行,uploadify的处理文件ashx能获取JS的formdata的日期给重命名文件名,但是aspx.cs却不能获取,用Request.Form或其他都不行……求教 <script type="text/javascript">
$(function () {
var time = new Date;
$('#custom_file_upload').uploadify({
'buttonImage': 'images/browse-btn.png',
'swf': 'js/uploadify.swf',
//'uploader': 'Upload.ashx?date=' + time.getTime(),
'uploader': 'Upload.ashx',
'multi': false, //是否允许多选
'auto': true, //是否允许自动上传
'fileTypeExts': '*.mp4',
'fileTypeDesc': '视频文件',
'queueID': 'custom-queue',
'method': 'post',
'progressData': 'speed',
'queueSizeLimit': 999, //允许同时上传文件数量
'uploadLimit': 999, //允许上传文件总数,指打开一次浏览器
'fileSizeLimit': '30MB', //限制单个文件大小,限制IIS大小请到Web.Config修改
'removeCompleted': true, //上传完成后是否自动消失
'formData': { 'date': time.getTime() }, 'onUploadStartt': function (file) {
$('#uploadify').uploadifySettings('formData', { 'date': $('#data').val });
}, 'onUploadComplete': function (file) { },
'onQueueComplete': function (file) {
alert('上传完毕!');
},
'onUploadError': function (file, errorCode, errorMsg, errorString) {
alert('视频 ' + file.name + ' 上传失败: ' + errorString);
}
// 你的配置
});
});
</script>ASHX处理public void ProcessRequest(HttpContext context)
{
string addTime = context.Request["date"];
HttpPostedFile file = context.Request.Files["Filedata"];
string uploadpath = context.Server.MapPath("Upload\\"); //文件上传目录 if (file != null)
{
if (!Directory.Exists(uploadpath))
{
Directory.CreateDirectory(uploadpath);
}
file.SaveAs(uploadpath + addTime + file.FileName.Substring(file.FileName.LastIndexOf('.')));
}
} public bool IsReusable
{
get
{
return false;
}
}后台处理public partial class M_Upload : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ } protected void UploadBtn (object sender, EventArgs e)
{
//获取当前时间
string addTime = Request.Form["data"];
//获取用户名
//string userName = Session["userName"].ToString();
//获取视频名称
string videoTitle = txtTitle.Text;
//获取视频内容
string videoContent = txtContent.Text;
//重命名上传的文件(下面是专门图像上传)
UploadCover.Rename = new string[Request.Files.Count];
for (int i = 0; i < Request.Files.Count; i++)
{
UploadCover.Rename[i] = addTime;
}
//UploadCover.ArrThumbSize = new string[] { "300,300", "200,200", "100,100" };
UploadCover.Save();
if (UploadCover.Error != null)
{
ShowHtml.Text = UploadCover.Error;
return;
}
string[] upath = UploadCover.GetFilePath;
for (int i = 0; i < upath.Length; i++)
{
if (UploadCover.GetThumbPath[i] != null)
{
string[] tpath = UploadCover.GetThumbPath[i];
for (int n = 0; n < tpath.Length; n++)
{
ShowHtml.Text += "<img src=\"" + tpath[n] + "\" alt=\"\" /><br /><br />";
}
}
} //获取视频转换后所保存的路径及文件名
string playFile = "Upload/" + addTime + ".mp4";
//获取图片所保存的路径及名称
string imgFile = "Upload/" + addTime + ".jpg";
//获取视频路径
string videoPath = playFile;
//获取图片路径
string videoPicture = imgFile;
//获取视频的类型
string videoType = SelectList.SelectedItem.Text;
//编写SQL语句将视频的详细信息添加到数据库中
string sqlInsert = "insert into Movies values('" + videoType +"','" + videoTitle + "','" + videoContent + "','" + videoPicture +
"','" + videoPath + "','" + addTime+"','" + 0 +"','')";
if (DB.execSql(sqlInsert))
{
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('上传成功!');</script>");
}
else ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('上传失败!');</script>"); }
}
主要是想让图片和视频文件名一致,并存入数据库里……
$(function () {
var time = new Date;
$('#custom_file_upload').uploadify({
'buttonImage': 'images/browse-btn.png',
'swf': 'js/uploadify.swf',
//'uploader': 'Upload.ashx?date=' + time.getTime(),
'uploader': 'Upload.ashx',
'multi': false, //是否允许多选
'auto': true, //是否允许自动上传
'fileTypeExts': '*.mp4',
'fileTypeDesc': '视频文件',
'queueID': 'custom-queue',
'method': 'post',
'progressData': 'speed',
'queueSizeLimit': 999, //允许同时上传文件数量
'uploadLimit': 999, //允许上传文件总数,指打开一次浏览器
'fileSizeLimit': '30MB', //限制单个文件大小,限制IIS大小请到Web.Config修改
'removeCompleted': true, //上传完成后是否自动消失
'formData': { 'date': time.getTime() }, 'onUploadStartt': function (file) {
$('#uploadify').uploadifySettings('formData', { 'date': $('#data').val });
}, 'onUploadComplete': function (file) { },
'onQueueComplete': function (file) {
alert('上传完毕!');
},
'onUploadError': function (file, errorCode, errorMsg, errorString) {
alert('视频 ' + file.name + ' 上传失败: ' + errorString);
}
// 你的配置
});
});
</script>ASHX处理public void ProcessRequest(HttpContext context)
{
string addTime = context.Request["date"];
HttpPostedFile file = context.Request.Files["Filedata"];
string uploadpath = context.Server.MapPath("Upload\\"); //文件上传目录 if (file != null)
{
if (!Directory.Exists(uploadpath))
{
Directory.CreateDirectory(uploadpath);
}
file.SaveAs(uploadpath + addTime + file.FileName.Substring(file.FileName.LastIndexOf('.')));
}
} public bool IsReusable
{
get
{
return false;
}
}后台处理public partial class M_Upload : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ } protected void UploadBtn (object sender, EventArgs e)
{
//获取当前时间
string addTime = Request.Form["data"];
//获取用户名
//string userName = Session["userName"].ToString();
//获取视频名称
string videoTitle = txtTitle.Text;
//获取视频内容
string videoContent = txtContent.Text;
//重命名上传的文件(下面是专门图像上传)
UploadCover.Rename = new string[Request.Files.Count];
for (int i = 0; i < Request.Files.Count; i++)
{
UploadCover.Rename[i] = addTime;
}
//UploadCover.ArrThumbSize = new string[] { "300,300", "200,200", "100,100" };
UploadCover.Save();
if (UploadCover.Error != null)
{
ShowHtml.Text = UploadCover.Error;
return;
}
string[] upath = UploadCover.GetFilePath;
for (int i = 0; i < upath.Length; i++)
{
if (UploadCover.GetThumbPath[i] != null)
{
string[] tpath = UploadCover.GetThumbPath[i];
for (int n = 0; n < tpath.Length; n++)
{
ShowHtml.Text += "<img src=\"" + tpath[n] + "\" alt=\"\" /><br /><br />";
}
}
} //获取视频转换后所保存的路径及文件名
string playFile = "Upload/" + addTime + ".mp4";
//获取图片所保存的路径及名称
string imgFile = "Upload/" + addTime + ".jpg";
//获取视频路径
string videoPath = playFile;
//获取图片路径
string videoPicture = imgFile;
//获取视频的类型
string videoType = SelectList.SelectedItem.Text;
//编写SQL语句将视频的详细信息添加到数据库中
string sqlInsert = "insert into Movies values('" + videoType +"','" + videoTitle + "','" + videoContent + "','" + videoPicture +
"','" + videoPath + "','" + addTime+"','" + 0 +"','')";
if (DB.execSql(sqlInsert))
{
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('上传成功!');</script>");
}
else ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('上传失败!');</script>"); }
}
主要是想让图片和视频文件名一致,并存入数据库里……
using System.Web.Services;2.加这样的代码:
[WebMethod]
public static void UploadBtn (参数?)
public static void UploadBtn(string data)
{
string addTime = data;
}
这样改吗?
但是下面addTime提示不存在名称