Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

asp code to display a file on the web server

Posted on 2014-02-09
2
Medium Priority
?
477 Views
Last Modified: 2014-02-13
I have the following code
<!--#include file="include/dbcommon.asp"-->
<!--#include file="include/OrderImage_variables.asp"-->
<%
if SESSION("UserID")="" or not CheckSecurity(SESSION("_" & strTableName & "_OwnerID"),"Search")then
	response.Redirect "login.asp"
	response.End
end if

Response.Expires = 0
Response.Buffer = True
Response.Clear

strFilename=REQUEST.querystring("filename")
ext=mid(strFilename,len(strFilename)-4)

select case ext
	case ".asf"	ctype = "video/x-ms-asf"
	case ".avi" ctype = "video/avi"
	case ".doc" ctype = "application/msword"
	case ".zip" ctype = "application/zip"
	case ".xls" ctype = "application/vnd.ms-excel"
	case ".gif" ctype = "image/gif"
	case ".jpg" ctype = "image/jpeg"
	case "jpeg" ctype = "image/jpeg"
	case ".wav" ctype = "audio/wav"
	case ".mp3" ctype = "audio/mpeg3"
	case ".mpg" ctype = "video/mpeg"
	case "mpeg" ctype = "video/mpeg"
	case ".rtf" ctype = "application/rtf"
	case ".htm" ctype = "text/html"
	case "html" ctype = "text/html"
	case ".asp" ctype = "text/asp"
	case else ctype = "application/octet-stream"
end select

field = REQUEST.querystring("field")
if not CheckFieldPermissions(field,"") then response.End

'//	construct sql

set keys = CreateObject("Scripting.Dictionary")
keys.Add ("ImageID"),postvalue("key1")
where=KeyWhere(keys,"")


dbConnection=""
db_connect()
Set rs = server.CreateObject("ADODB.Recordset")


sql = gSQLWhereAdd(where)

rs.Open sql,dbConnection, 1,2

if rs.EOF then
	rs.Close
	response.Redirect "login.asp"
	response.End
end if

binTemp = rs(field).GetChunk(42000000)

if IsNull(binTemp) then
	response.end
end if

Response.ContentType = ContentType
Response.AddHeader "Content-Disposition", "attachment;Filename=""" & strFileName & """"
Response.AddHeader "Content-Length", lenb(db_stripslashesbinary(binTemp))

Response.BinaryWrite binTemp

rs.Close
response.End

%> 

Open in new window


which opens a file stored in a database blob field.  we want to move the images mostly pdf out of the db and into a directory off the root "c:\jobimages

how can this code be changed to pull the files

example of new db

jobnumber    imagepath  imagename

12323               c:\jobimages                  dogs.pdf

the only thing that will be stored in the db is a pointer to the file
0
Comment
Question by:rmardis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 33

Accepted Solution

by:
Big Monty earned 2000 total points
ID: 39846365
first, make sure your web site has access to c:\jobimages, you may want to create a virtual folder for this. Second, once you've ready the path to he folder, just do a response.redirect to it and it'll open the file up:

filePath = rs("path")
Response.Redirect Server.MapPath( filePath )     '-- assuming the file is using absolute paths
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 39849082
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Via a live example, show how to shrink a transaction log file down to a reasonable size.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question