---------------------------------------------------------------
你看看这个吧:
2.CHINA ASP UPLOAD所有一切都已经写好了,这是一个dll,它自动将Request里的二进制(文件)内容读取出来,还能读取表单域,不是我做的:),觉得好用给你参考咯。一段代码。
---------------js新闻类界面类(不包含数据库操纵类),UI.js
// Class UI
function NewsForm()
{
this.FormStr = "";
this.FormTitle = "";
this.FormNewsSort = "";
this.FormAuthor = "";
this.FormCopySign = "";
this.FormCopyRightSign = "";
this.FormContent = "";
this.FormNewsPic = "";
this.StaticSort = new ActiveXObject("Microsoft.XMLDOM");
this.StaticSort.load(Server.MapPath("./").substr(0,15) + "Upload\\News\\NewsSort.xml");
this.ShowForm = NewsForm_ShowForm;
this.SaveForm = NewsForm_SaveForm;
}
function NewsForm_ShowForm()
{
this.FormStr += '
1<table>\n';
2this.FormStr += '<form action="UIUploadSample.asp" enctype="multipart/form-data" method="post" name="Upload">\n';
3this.FormStr += '<input name="CopyrightInfo" type="hidden" value="http://www.chinaasp.com"/>\n';
4this.FormStr += '<input name="IsPostBack" type="hidden" value="1"/>\n';
5this.FormStr += '<tr>\n';
6this.FormStr += ' <td>ÐÂÎűêÌâ</td>\n';
7this.FormStr += ' <td><input name="NewsTitle" type="text"/></td>\n';
8this.FormStr += '</tr>\n';
9this.FormStr += '<tr>\n';
10this.FormStr += ' <td>ÐÂÎÅÀàÐÍ</td>\n';
11this.FormStr += ' <td><select name="NewsSort">\n';
12for (var i=0;i<this.staticsort.childnodes[1].childnodes.length '"="" )="" +="" ;i++="" this.formstr="" this.staticsort.childnodes[1].childnodes[i].childnodes[0].text="" {="">' + this.StaticSort.childNodes[1].childNodes[i].childNodes[1].text + '\n';
13}
14this.FormStr += ' </this.staticsort.childnodes[1].childnodes.length></select></td>\n';
15this.FormStr += '</tr>\n';
16this.FormStr += '<tr>\n';
17this.FormStr += ' <td>×÷Õß</td>\n';
18this.FormStr += ' <td><input name="Author" type="text"/></td>\n';
19this.FormStr += '</tr>\n';
20this.FormStr += '<tr>\n';
21this.FormStr += ' <td>³ö´¦</td>\n';
22this.FormStr += ' <td><input name="CopySign" type="text"/></td>\n';
23this.FormStr += '</tr>\n';
24this.FormStr += '<tr>\n';
25this.FormStr += ' <td>°æÈ¨</td>\n';
26this.FormStr += ' <td><input name="CopyRightSign" type="text"/></td>\n';
27this.FormStr += '</tr>\n';
28this.FormStr += '<tr>\n';
29this.FormStr += ' <td>ÐÂÎÅͼƬ</td>\n';
30this.FormStr += ' <td><input name="NewsPic" type="file"/></td>\n';
31this.FormStr += '</tr>\n';
32this.FormStr += '<tr>\n';
33this.FormStr += ' <td>ÄÚÈÝ</td>\n';
34this.FormStr += ' <td><textarea cols="20" name="NewsContent" rows="6"></textarea></td>\n';
35this.FormStr += '</tr>\n';
36this.FormStr += '<tr>\n';
37this.FormStr += ' <td align="center" colspan="2"><input type="submit"/><input type="reset"/></td>\n';
38this.FormStr += '</tr>\n';
39this.FormStr += '</form>\n';
40
41Response.Write(this.FormStr);
42}
43
44function NewsForm_SaveForm()
45{
46var fu = new ActiveXObject("ChinaASP.UpLoad");
47
48this.FormTitle = fu.Form("NewsTitle").value;
49this.FormNewsSort = fu.Form("NewsSort").value;
50this.FormAuthor = fu.Form("Author").value;
51this.FormCopySign = fu.Form("CopySign").value;
52this.FormCopyRightSign = fu.Form("CopyRightSign").value;
53this.FormContent = fu.Form("NewsContent").value;
54
55if (fu.Files(1).FileName != "")
56{
57this.FormNewsPic = fu.Files(1);
58}
59
60var NewsToAdd = new News();
61
62NewsToAdd.Title = this.FormTitle;
63NewsToAdd.NewsSort = this.FormNewsSort;
64NewsToAdd.Author = this.FormAuthor;
65NewsToAdd.CopySign = this.FormCopySign;
66NewsToAdd.CopyRightSign = this.FormCopyRightSign;
67NewsToAdd.Content = this.FormContent;
68
69if (fu.Files(1).FileName != "")
70{
71NewsToAdd.NewsPic = this.FormNewsPic;
72}
73
74NewsToAdd.AddNews();
75}
76
77\------------------------------填写页面*****.asp
78
@ language="Jscript"
1<script language="javascript" runat="server" src="UI.js"></script>
2<style>
3td
4{
5font-size: 12;
6}
7th
8{
9font-size: 12;
10}
11.LargeListHead
12{
13background-color: #CCCCCC;
14}
15.LargeListRow1
16{
17background-color: #EEEEEE;
18}
19.NavButton
20{
21border: 0 solid;
22background-color: #FFFFFF;
23}
24</style>
var tmp = new NewsForm();
tmp.ShowForm();
1
2\---------------------------------生成新闻页面UIUploadSample.js
3
@ language="Jscript"
1<script language="javascript" runat="server" src="Classes.js"></script>
2<script language="javascript" runat="server" src="UI.js"></script>
var tmp = new NewsForm();
tmp.SaveForm();
1
2
3\---------------------------------------------------------------
4
5chinaasp.upload的调用在News类里了,再贴一个片段吧。
6
7// Class News
8
9function News()
10{
11this.NewsId = 0;
12this.Title = "";
13this.NewsSort = "";
14this.KeyWords = "";
15this.SendDate = getSysTime();
16this.Author = "";
17this.CopySign = "";
18this.CopyRightSign = "";
19this.Content = "";
20this.NewsPic = null; // Type ChinaASP.UpLoad.File
21
22this.AddNews = News_AddNews;
23this.DelNews = News_DelNews;
24this.UpdNews = News_UpdNews;
25this.GetNews = News_GetNews;
26}
27
28function News_AddNews()
29{
30var dbTab = new DbTable("NEWS");
31
32this.NewsId = dbTab.GetMaxSeq("NEWS_ID");
33
34var Sacc = new SimpleAccess();
35
36Sacc.QueryString = "insert into NEWS values(" + this.NewsId +",";
37Sacc.QueryString += "'" + this.NewsSort + "',";
38Sacc.QueryString += "'" + this.Title + "',";
39Sacc.QueryString += "'" + this.KeyWords + "',";
40Sacc.QueryString += "'" + this.SendDate + "',";
41Sacc.QueryString += "'" + this.Author + "',";
42Sacc.QueryString += "'" + this.CopySign + "',";
43Sacc.QueryString += "'" + this.CopyRightSign + "')";
44
45Sacc.ExecuteOtherQuery();
46
47var fso = new ActiveXObject("Scripting.FileSystemObject");
48
49fso.CreateFolder(getServerPath() + "Upload\\\News\\\" + this.NewsId + "\\\");
50
51var XMLDOM = new ActiveXObject("Microsoft.XMLDOM");
52
53var DomStr = "";
54
55DomStr += '<?xml version="1.0" encoding="UTF-8"?>\n';
56DomStr += '<newsroot newsid="' + this.NewsId + '">\n';
57DomStr += '<content>'+ Replace(this.Content) +'</content>\n';
58DomStr += '</newsroot>\n';
59
60XMLDOM.loadXML(DomStr);
61XMLDOM.save(getServerPath() + "Upload\\\News\\\" + this.NewsId + "\\\Content.xml")
62
63if (this.NewsPic != null)
64{
65this.NewsPic.SaveAS(getServerPath() + "Upload\\\News\\\" + this.NewsId + "\\\NewsPic" + this.NewsPic.FileName.substr(this.NewsPic.FileName.length-4,4));
66}
67}
68
69function News_DelNews()
70{
71var Sacc = new SimpleAccess();
72
73Sacc.QueryString = "delete from NEWS where NEWS_ID = " + this.NewsId;
74
75Sacc.ExecuteOtherQuery();
76}
77
78function News_UpdNews()
79{
80var Sacc = new SimpleAccess();
81
82Sacc.QueryString = "update NEWS set ";
83Sacc.QueryString += "NEWS_SORT = '" + this.NewsSort + "',";
84Sacc.QueryString += "TITLE = '" + this.Title + "',";
85Sacc.QueryString += "KEY_WORDS = '" + this.KeyWords + "',";
86Sacc.QueryString += "AUTHOR = '" + this.Author + "',";
87Sacc.QueryString += "COPY_SIGN = '" + this.CopySign + "',";
88Sacc.QueryString += "COPYRIGHT_SIGN = '" + this.CopyRightSign + "' ";
89Sacc.QueryString += "where NEWS_ID = " + this.NewsId;
90
91Sacc.ExecuteOtherQuery();
92
93var XMLDom = new ActiveXObject("Microsoft.XMLDOM");
94
95XMLDom.load(ServerPath + "Upload\\\News\\\" + this.NewsId + "\\\Content.xml");
96
97XMLDom.childNodes[1].childNodes[0].text = this.Content;
98
99XMLDom.save(ServerPath + "Upload\\\News\\\" + this.NewsId + "\\\Content.xml");
100}
101
102function News_GetNews()
103{
104var Sacc = new SimpleAccess();
105
106Sacc.QueryString = "select * from NEWS where NEWS_ID = " + this.NewsId;
107
108Sacc.ExecuteSelectQuery();
109
110this.NewsId = Sacc.QueryResult(0);
111this.NewsSort = Sacc.QueryResult(1);
112this.Title = Sacc.QueryResult(2);
113this.KeyWords = Sacc.QueryResult(3);
114this.SendDate = Sacc.QueryResult(4);
115this.Author = Sacc.QueryResult</table>