Solved

asp code to display a file on the web server

Posted on 2014-02-09
2
449 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
2 Comments
 
LVL 32

Accepted Solution

by:
Big Monty earned 500 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This article discusses how to create an extensible mechanism for linked drop downs.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now