首页 新闻 搜索 专区 学院

关于动态上传多个图片的问题,AJAX高手请进啊,帮帮忙,急用!!!万分感激!

0
悬赏园豆:15 [已关闭问题]

实在没有办法,我就这么点专家分了,全压上了啊!

最近做项目,需要用户上传多张图片,同时设置每张图片的name,和description。可是我不知道怎么做,在网上下载了个代码,但是它只能动态生成上传的控件,不能动态的生成填写name和description的控件,下面是它的页面代码

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FileUpload.aspx.cs" Inherits="FileUpload" %>
<!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>
<title>Multi File Upload</title>
</head>
<body>
<form id="form1" runat="server" enctype="multipart/form-data">
<div id="mainDiv">
<p id="upload-area">
<input id="File1" type="file" runat="server" size="60" />
</p>

<input id="AddFile" type="button" value="Add file" onclick="addFileUploadBox()" />
<p><asp:Button ID="btnSubmit" runat="server" Text="Upload Now" OnClick="btnSubmit_Click" /></p>
</div>
<script type="text/javascript">
function addFileUploadBox()
{
if (!document.getElementById || !document.createElement)
return false;

var uploadArea = document.getElementById ("upload-area");

if (!uploadArea)
return;

var newLine = document.createElement ("br");
uploadArea.appendChild (newLine);

var newUploadBox = document.createElement ("input");

// Set up the new input for file uploads
newUploadBox.type = "file";
newUploadBox.size
= "60";

// The new box needs a name and an ID
if (!addFileUploadBox.lastAssignedId)
addFileUploadBox.lastAssignedId
= 100;

newUploadBox.setAttribute (
"id", "dynamic" + addFileUploadBox.lastAssignedId);
newUploadBox.setAttribute (
"name", "dynamic:" + addFileUploadBox.lastAssignedId);
uploadArea.appendChild (newUploadBox);
addFileUploadBox.lastAssignedId
++;
}


</script>
</form>
</body>
</html>

下面是后台的处理代码
Code
protected void btnSubmit_Click(object sender, EventArgs e)
{
HttpFileCollection uploads
= HttpContext.Current.Request.Files;

for (int i = 0; i < uploads.Count; i++)
{
HttpPostedFile upload
= uploads[i];

if (upload.ContentLength == 0)
continue;

string c = System.IO.Path.GetFileName(upload.FileName); // We don't need the path, just the name.

try
{
upload.SaveAs(
"C:\\UploadedUserFiles\\" + c);
}
catch (Exception Exp)
{

}
}
Server.Transfer(
"UploadComplete.aspx");
}

我需要知道如何与上传控件一起添加填写name和description的控件,并且在后台如何获取相对应的值,谢谢。我就这点专家分了,高手们帮帮忙啊!万分感激!!!

天堂口的主页 天堂口 | 小虾三级 | 园豆:514
提问于:2008-10-14 20:31
< >
分享
其他回答(1)
0

http://www.fyneworks.com/jquery/multiple-file-upload/#tab-Examples

楼主可以在这个的基础上改一下

张荣华 | 园豆:2020 (老鸟四级) | 2008-10-15 10:41
0

HHFpicUpload 高级图片上传控件

http://www.cnblogs.com/zhway/archive/2006/10/27/540901.html

RicoRui | 园豆:3663 (老鸟四级) | 2008-10-15 11:03
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册