download file

Results 1 to 2 of 2

Thread: download file

  1. #1
    Join Date
    Dec 1969

    Default download file

    Hi,<BR><BR> i have a listings of files which I want to be able to click (mainly .ppt and .pdf)<BR>I do not want the file to open directly, I want a pop up box to select to save or open. I have this script which works fine. <BR><BR>The problem I have is, if i choose to open the file.. after viewing the file, i close the file window, then go back to the listings page, click on the same link, or other links, i get a blank page with a number "0" on it.<BR>Does anyone know why or anyone knows of any new scripts that i can use? PLease help me thankie!<BR><BR>&#060;a href="../../common/download.asp?File=&#060;%=filepath%&#062;&Name=&#0 60;%=trim(rsfiles("file_name"))%&#062;&Size=&#060; %=strFilesSize%&#062;" &#062;<BR><BR><BR>This is the download.asp file<BR>-----------------------------<BR>&#060;%<BR>Response.Buffer = True<BR><BR>filepath = Request.QueryString("File")<BR>filename = Request.QueryString("Name")<BR>filesize = Request.QueryString("Size")<BR>user_id = Request.QueryString("user_id")<BR>strFileName=file name<BR><BR>strFilePath=filepath<BR>Response.write "<BR>"& strFilePath<BR><BR>Response.Write filepath<BR>Response.Write "<BR>" & strFileName<BR><BR>strFileSize = filesize<BR><BR><BR>&#039;Response.Write "<BR>" & strFileSize<BR><BR>Const adTypeBinary = 1<BR>Response.Clear<BR>Set objStream = Server.CreateObject("ADODB.Stream")<BR>objStream.O pen<BR>objStream.Type = adTypeBinary<BR>objStream.LoadFromFile strFilePath<BR>strFileType = "application/octet-stream" &#039; change to the correct content type for your file<BR>Response.AddHeader "Content-Disposition", "attachment; filename=" & strFileName<BR>Response.AddHeader "Content-Length", strFileSize<BR>Response.Charset = "UTF-8"<BR>Response.ContentType = strFileType<BR>Response.BinaryWrite objStream.Read<BR>Response.Flush<BR>objStream.Clos e<BR>Set objStream = Nothing<BR>%&#062;<BR><BR>twinkle

  2. #2
    Join Date
    Dec 1969

    Default Interesting...

    I knew this could happen if you used a call to a JavaScript function in your HREF.<BR><BR>That is, if you do:<BR> &#060;A HREF="javascript:doSomething( );"&#062;...&#060;/A&#062;<BR>then when the JS function is done you will end up with that zero. This is because after the JS function is done it returns a zero value...and then the HREF uses that zero value!!!<BR><BR>I didn&#039;t think the same thing would happen with this kind of download, but I admit to never having tried it.<BR><BR>So...<BR><BR>The fix *MAY* be essentially the same as what I suggest for fixing the JS problem.<BR><BR>************<BR><BR>&#060;%<BR>&#0 39; you REALLY should URLEncode the names! If they have spaces <BR>&#039; or other special characters in them they can mess up the URL!<BR>&#039;<BR>url = "../../common/download.asp?File=" & Server.URLEncode(filepath) _<BR> & "&Name=" & Server.URLEncode(Trim(rsfiles("file_name"))) _<BR> & "&Size=" & strFilesSize<BR>%&#062;<BR><BR>&#060;A HREF="#" onClick="location.href=&#060;%=url%&#062;; return false;"&#062; ... &#060;/A&#062;<BR><BR>************<BR><BR>See the trick? After specifying that change of location, you do the return false and the prevents that actual HREF from being used! Same as returning false from an onSubmit of a form or an onClick of a submit button.<BR><BR>100% untested in this environment! Do let us know if it works.<BR><BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts