网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > ASP实例
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.深入讲解 ASP+ 验证(三).
.无组件上传图片至SQLSERVER数据库.
.聊天室建设详解四.
.asp制作显示IP图片.
.浅谈TeeChart组件在ASP中的应用.
.各种存储过程使用指南.
.使用AspImage制作图形(二).
.轻松实现将上传图片到数据库.
.纯ASP代码之公历转农历实现(含属.
.不用图像组件的ASP图像计数器.
.使用JScript.NET创建asp.net页面.
.数字和字母组合并生成图片的验证.
.asp实现同网站不同目录帮定不同域.
.网络寻呼机数据库版显示消息show.
.用多种方法制作WEB页面的计数器.
.用Access制作一个功能完善的论坛.
.一个ASP.NET+XML留言本例子.
.利用ASP.NET设计FTP文件上传(下).
.一个检查E文拼写错误的Code.
.调用DirectX的组件实现的时钟.

如何用SAFileUp上传文件?

发表日期:2001-6-28


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

%>


上一篇:用ASP实现号码转换程序实例 人气:9548
下一篇:用Jmail做收取邮件附件的程序 人气:12482
浏览全部上传的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐