欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

如何用SAFileUp上传文件?

程序员文章站 2022-07-03 14:05:23
how do i upload files to the database with safileup?  dont do it! use safileup t...
how do i upload files to the database with safileup?  
dont 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.. 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:  https:// </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"