您的位置:首页网页设计ASP实例 → 如何用SAFileUp上传文件?

如何用SAFileUp上传文件?

时间:2004/11/7 2:56:00来源:本站整理作者:蓝点我要评论(0)

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.

















Category









Alternate Text for banner:




URL:  http://




Get Add:



      





      











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 "" & rs("ALT") & ""

End iF

rs.close

set rs = nothing



%>






相关阅读 Windows错误代码大全 Windows错误代码查询激活windows有什么用Mac QQ和Windows QQ聊天记录怎么合并 Mac QQ和Windows QQ聊天记录Windows 10自动更新怎么关闭 如何关闭Windows 10自动更新windows 10 rs4快速预览版17017下载错误问题Win10秋季创意者更新16291更新了什么 win10 16291更新内容windows10秋季创意者更新时间 windows10秋季创意者更新内容kb3150513补丁更新了什么 Windows 10补丁kb3150513是什么

文章评论
发表评论

热门文章 没有查询到任何记录。

最新文章 迅雷新手完全入门手册 asp下面javascript上传图片限制格式大小方法告诉大家网页弹出窗口应用总结ASP常见错误类型大全asp常见错误分析和解决办法

人气排行 总是弹出visual studio 实时调试器 三种解决SQLSERVER存储过程及调用详解Asp获取真实IP地址ASP中连接Mssql的几种方法一个简单好用的UBB编辑器(含代码)如何用Split将字符串转换为数组并获取数组下ASP防止表单重复提交的办法告诉你免费的简单聊天室源代码