pdf file within a psp file

Snitz™ Forums 2000
https://forum.snitz.com/forumTopic/Posts/67118?pagenum=1
05 November 2025, 07:25

Topic


cadfhs
pdf file within a psp file
24 May 2008, 11:07


Hi
Is there anyone out there who can solve this for me? I would like to put pdf files inside files with a psp extension. The reason is that I want to restrict access to the pdf's to members of the society but don't want them to have to enter a password for every pdf. My server don't support .htpasswd so I can not use that, but have code for a password that uses php script. cheers
Neil<

 

Replies ...


Shaggy
26 May 2008, 04:41


psp?
Quickest & easiest way to do what you want is to stream the files through an ASP file that checks whether or not the visitor is logged in before serving the file.
<
cadfhs
26 May 2008, 05:21


Shaggy, cheers for this, but I am at a lost how to do it.

Currently the links to these pdf's are on a web page which has a password on it, but I am not 100% happy that this is secure.<
Shaggy
26 May 2008, 05:33


This would be the basics of it, making the assumption that you're using the Snitz variables. You'll need to create a database connection in this file (you can't include inc_header.asp or any other files that use response.write but you will need to include inc_func_common.asp for the chkstring function) and you'd need to drop the filename of each PDF into a table in that database (FILES, below).
Code:
dim objStream,intPdf,strPdf
if MemberId>0 then
intPdf=request.querystring("pdf")
if len(intPdf)>0 and isnumeric(intPdf) then
intPdf=clng(intPdf)
set objRs=objConn.execute("SELECT FILENAME FROM FILES WHERE FILE_ID="&intPdf)
if not objRs.eof then
strPdf=chkstring(objRs("FILENAME"),"urlpath")
server.scripttimeout=300
set objStream=server.createObject("ADODB.Stream")
objStream.open
objStream.type=1
objStream.loadfromfile server.mappath("/pdfs/"&strPdf)
response.addheader "content-disposition","attachment;filename="&strPdf
response.charset="UTF-8"
response.contenttype="application/x-pdf"
response.binarywrite objStream.read
objStream.close:set objStream=nothing
end if
objRs.close:set objRs=nothing
end if
end if
<
cadfhs
26 May 2008, 11:04


Thanks Shaggy
I will have a think about this and see what I can do. Cheers
Neil<
© 2000-2021 Snitz™ Communications