We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Why does this download pdf file code from a non-direct link damage the file?

RepressedRadar
on
Medium Priority
222 Views
Last Modified: 2012-08-14
The code allows download.
But when the file is opened.
The file is damaged.
<%@Language="VBScript"%>
<%Option Explicit%>
 
	<%
	Dim adoStream, stream, fileName, mimeType
	Set adoStream = Server.CreateObject("ADODB.Stream")
 
	fileName = Request.QueryString("file")
	mimeType = Request.QueryString("mime")
 
	adoStream.Open()
	adoStream.Type = adTypeBinary
	'adoStream.LoadFromFile Server.MapPath(fileName)
	adoStream.LoadFromFile Server.MapPath("/s1QZAkAeAKT1chsRu/" & fileName)
	
	
	
	
	If adoStream.Type = adTypeBinary Then
	stream = adoStream.Read()
	Else
	stream = adoStream.ReadText()
	End If
	adoStream.Close()
	Set adoStream = Nothing
 
 
	Response.Buffer = True
	Response.AddHeader "content-disposition", "attachment; filename=" & fileName
	Response.AddHeader "content-length", Len(stream)
 
	Response.ContentType = mimeType
	Response.BinaryWrite stream
	Response.Flush
 
	%>

Open in new window

Comment
Watch Question

Don't ask why, but try adding the below to the very top of your page and see what happens?   If it works you will need to redo your code as this is a special call for PDFs files and will most likely break all other file types - the whole thing gets a bit technical and I can't remember where I read the article that suggested this.
<!--METADATA TYPE="TypeLib" UUID="{414FEE4B-2879-4090-957E-423567FFCFC6}"-->

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.