首页 >> 读书频道 >> 电脑 >> 如何用SAFileUp上传文件?
 
· 用ASP实现号码转换程序
· 用ASP实现文档资料管理
· 用asp怎样编写文档搜索
· 用asp怎样编写文档搜索
· 用asp怎样编写文档搜索
· 用asp怎样编写文档搜索
· 用asp怎样编写文档搜索
· 用asp怎样编写文档搜索
· 用ASP+XML打造留言
· 用ASP+XML打造留言
· 用ASP+XML打造留言
· 使用AspImage制作
 
· 美容养颜手册
· 加油金顺剧情分集介绍完整
· 红楼梦:120回全本[清
· 素质教育在美国
· 全唐诗卷四十六
· 韩剧《布拉格恋人》剧情介
· 夜航船[作者:明·张岱]
· 局外人[作者:韩·可爱淘
· 现场流行病学
· 源氏物语[日本:紫式部]
· 武林寓言故事
· 2006高考录取规则
 
· (出租)中动商场部分及写
· (出租)中动动漫基地&#
· 喜剧学院
· 《善德女王》剧情介绍
· 魔女18号 剧情
· 丑女无敌剧情介绍
· 魔女幼熙剧情介绍
· 龙游天下剧情介绍
· 震撼世界的七日剧情介绍
· 静静的白桦林剧情介绍
· 心情日记—老公今天我想对
· 旗舰剧情介绍
欢迎来到月影社区!如果您觉得这里不错,请推荐给您的朋友们。月影社区:http://wf66.com/

如何用SAFileUp上传文件?


查看有无更新版本

关键字:ASP实例 2006-9-9

 

How Do I Upload Files to the database with SAFileUp? 
Don't do it! Use SAFileUp to upload the files to the server but do not store the image in the database. Instead store the path to the file. Better yet if the images will sit in the same folder just store the actual file name. Uploading the entire image to the database wastes too many resources. You need to upload the image in binary format which is slow. You also waste all that extra database space to store the image. Then you lose speed retrieving it.
These are the requirements for uploading files with SAFileup.
1] You need SAFileUp installed on the server. 2] You need Read, Write, and Change permissions on the directory you are going to save the pictures to. In my example I named the folder "Mypictures". Contact your ISP to set this up for you.
This is the web form - upload.asp. Notice the multipart/form-data. We are not just uploading text here. We are pulling files from the hard drive. Special rules and instructions apply. INPUT TYPE="file" gives us the browser button on the screen which lets us access the hard drive.
<TABLE><TR>
<TD valign='top'>
Category
</TD>
<TD>
<form enctype="multipart/form-data" method="post"  action="upload2.asp">
<INPUT TYPE="text"  NAME="categoryname">
</TD>
</TR>
<TR><TD align="right">
Alternate Text for banner:</TD>
<TD><INPUT TYPE="text"  NAME="alt">
</TD></TR>
<TR><TD align="right">
URL:  http:// </TD><TD><INPUT TYPE="text"  NAME="url">
</TD></TR>
<TR><TD align="right">
Get Add:</TD><TD><input type="file" name="f1"><br>
</TD></TR></TABLE>     
<BR><BR>
      <input type="submit"  NAME="submit"  value="submit">
</form>
 

The FORM Processing script - upload2.asp. Notice the upl.form("FORM_NAME"). you cannot use request.form to
retrieve form data when uploading files. You must reference the form elements with the File Upload object.
In this example it is "upl". <%
'You must have SAFileUp installed on the server
      Set upl = Server.CreateObject("SoftArtisans.FileUp")
      categoryname = trim(replace(upl.form("categoryname"),"'",""))
      alt = trim(replace(upl.form("alt"),"'",""))
      url = trim(replace(upl.form("url"),"'",""))
if categoryname = "" then
      response.write "You Must Enter a category name"
      response.end
End IF
NewFileName = Mid(upl.UserFilename, InstrRev(upl.UserFilename, "\") + 1)
'Rename file if file name already exists
      upl.CreateNewFile = true
'Do not overwrite existing files
'The folder the pictures will be saved in need Read, Write
'and Change permissions.  In this example it is "MyPictures"
      upl.SaveAs "D:\MyWebs\MyPictures\" & NewFileName
'Make sure we have the http:// extension
'remove it if it was already entered then re-add it
      path = NewFileName
      url = replace(url,"http://","")
      url = CStr("http://"&url)
'Save the image file name, not the actual image
      SQLin = "INSERT INTO MyPics (CategoryName,Alt,URL,Path)"
      SQLin = SQLin & "VALUES("&categoryname&",'"&alt&"','"&url&"','"&path&"')"
      DataConn.execute(SQLin)
response.write "File Uploaded"
     
%> 
 
Now retrieve the images from the database and display them wherever you want to use them. We will assume that we are grabbing categories from the query string and then pulling their images from the database. We know what folder we saved the pictures to therefore we can hardcode that information in. Now all we need
is the file name associated with the category. <%
catid = request.querystring("catid")
SQL = "Select Alt,URL,Path from Mypics where CategoryID = "&catid&""
set rs = DataConn.execute(SQL)
if not rs.eof then
  response.write "<IMG SRC='/MyPictures/" & rs("Path") & "'" & " ALT='" & rs("ALT") & "'>"
End iF
rs.close
set rs = nothing
%>

如何用SAFileUp上传文件?

[ 1 ]
如何用SAFileUp上传文件? num

打印本页 关闭

关于我们版权声明本站导航友情连结作品演示 TOP↑