asp upload控件使用基本入门
2009-08-05 10:45
411 查看
aspupload这个控件使用也比较简单,安装程序附带了几个例子,看完也基本熟悉使用了,如果只是项目中偶尔使用,只要记住几条就可以了。
一个简单的例子是:我们要做一个文件管理器,文件提交后将文件编号和文件名写入到数据库中。有两个页面组成:a.asp,b.asp.
<form method=post enctype="multipart/form-data" action=b.asp>
<input type=file name=filetosub>
<input type=text name=code size=10>
<input type=submit name=ok value=upload>
</form>
b.asp
<%
set upload=server.createobject("persits.upload")
count=upload.save("c:/upload")
set file=upload.files("filetosub")
mycn.execute"insert into tablefile (code,filename) select "&upload.form("code")&",'"&file.filename&"'
response.write count &"个文件被提交到c:/upload"
%>
这样就实现了文件的上传,但问题接着就来了:
1.如果我不想使用原来的文件名,我要自己定义呢,如何做?
2.如果我要一次提交多个文件呢?如何做?
3.如果我要提交的文件不是放在c:/upload下呢?
按照这种意图,我们修改一下a.asp
<form method=post enctype="multipart/form-data" action=b.asp>
<input type=file name=filetosub1>
<input type=file name=filetosub2>
<input type=file name=filetosub3>
<input type=text name=code size=10>
<input type=submit name=ok value=upload>
然后我们在b.asp中也做出一些修改:
<%
'数据库连接这里就不写了
set upload=server.createobject("persits.upload")
upload.save
for each file in upload.files
filenamestr="1111"&File.Filename
File.SaveAs "c:/upload/" & File.Filename
mycn.execute"insert into tablefile (code,filename) select "&upload.form("code")&",'"&filestr&"'"
next
%>
再继续,如果我们要把文件存储到数据库中呢,如何操作?
a.asp我们不需要做任何动作,只要修改b.asp
<%
set upload=server.createobject("persits.upload")
upload.save "c:/upload"
set file=upload.files("filetosub")
sql="insert into filedb (filecon,filename) value (?,'"&file.filename&"')"
file.todatabase mycn,sql
response.write"<script>alert('ok')</script>"
%>
既然存放到数据库中了就可能需要读取出来。
<%
set upload=server.createobject("persits.upload")
sql="select * from filedb where filename='"&filenamestr&"'"
rs1.open sql,mycn,2,3
if not rs1.eof then
upload.fromrecordset rs1("filecon").value,"c:/upload/"
end if
rs1.close
%>
一个简单的例子是:我们要做一个文件管理器,文件提交后将文件编号和文件名写入到数据库中。有两个页面组成:a.asp,b.asp.
<form method=post enctype="multipart/form-data" action=b.asp>
<input type=file name=filetosub>
<input type=text name=code size=10>
<input type=submit name=ok value=upload>
</form>
b.asp
<%
set upload=server.createobject("persits.upload")
count=upload.save("c:/upload")
set file=upload.files("filetosub")
mycn.execute"insert into tablefile (code,filename) select "&upload.form("code")&",'"&file.filename&"'
response.write count &"个文件被提交到c:/upload"
%>
这样就实现了文件的上传,但问题接着就来了:
1.如果我不想使用原来的文件名,我要自己定义呢,如何做?
2.如果我要一次提交多个文件呢?如何做?
3.如果我要提交的文件不是放在c:/upload下呢?
按照这种意图,我们修改一下a.asp
<form method=post enctype="multipart/form-data" action=b.asp>
<input type=file name=filetosub1>
<input type=file name=filetosub2>
<input type=file name=filetosub3>
<input type=text name=code size=10>
<input type=submit name=ok value=upload>
然后我们在b.asp中也做出一些修改:
<%
'数据库连接这里就不写了
set upload=server.createobject("persits.upload")
upload.save
for each file in upload.files
filenamestr="1111"&File.Filename
File.SaveAs "c:/upload/" & File.Filename
mycn.execute"insert into tablefile (code,filename) select "&upload.form("code")&",'"&filestr&"'"
next
%>
再继续,如果我们要把文件存储到数据库中呢,如何操作?
a.asp我们不需要做任何动作,只要修改b.asp
<%
set upload=server.createobject("persits.upload")
upload.save "c:/upload"
set file=upload.files("filetosub")
sql="insert into filedb (filecon,filename) value (?,'"&file.filename&"')"
file.todatabase mycn,sql
response.write"<script>alert('ok')</script>"
%>
既然存放到数据库中了就可能需要读取出来。
<%
set upload=server.createobject("persits.upload")
sql="select * from filedb where filename='"&filenamestr&"'"
rs1.open sql,mycn,2,3
if not rs1.eof then
upload.fromrecordset rs1("filecon").value,"c:/upload/"
end if
rs1.close
%>
相关文章推荐
- 安卓入门一之基本控件使用
- bootstarp入门二(基本控件的使用)
- Metro Style App开发快速入门 之基本控件使用总结
- [学习笔记] TensorFlow 入门之基本使用
- Flex 3快速入门: 构建高级用户界面 使用 Tree 控件
- webView控件基本使用(android)
- asp.ent MVC 的一些基本控件的使用
- IOS中UI控件的基本使用
- Android, 基本控件的使用
- Android JNI入门第五篇——基本数据类型使用
- CStatic控件的基本使用
- asp.net基本控件使用
- IOS 基本控件使用方法
- 使用 IntraWeb (12) - 基本控件之 TIWGradButton、TIWImageButton
- CStatic控件的基本使用
- iOS_基本控件_UITextField使用细则
- 译文:使用MVC5的Entity Framework 6入门(二)——实现基本的CRUD功能
- 使用 IntraWeb (17) - 基本控件之 TIWRadioButton、TIWRadioGroup、TIWCheckBox
- Android入门教程五十一之其他几种常用对话框基本使用
- arcgis api for flex 开发入门(四)Darw控件的使用<转>