#31
  1. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jun 2007
    Posts
    1
    Rep Power
    0

    download count?


    Hi there

    Great code and post, I've used it and have no trouble with it. I realise this thread is getting old so I don't expect much response!

    I'm trying to get a download count and have some trouble. It's simple enough to count how many downloads have been initiated, but I want to tell when a download has actually been completed.

    I thought that you could perhaps use response.isClientConnected to see if the client is still there after the download but that doesn't seem to work. Any ideas??

    Many thanks,
    Dylan
  2. #32
  3. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2925
    hi Dylan,

    this is very common problem and I fear there's no solution.
    the problem is the Server send the whole file to the browser
    and "forget" about it - it has no direct connection with the
    browser.
  4. #33
  5. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Sep 2007
    Posts
    2
    Rep Power
    0

    Thumbs up 3rd Party Download managers


    Thanks for making my life much easier with this post. Had sleeples nights thinking how to proceed...

    Works perfectly with default IE downloader.

    Is there any reason why DAP and other 3rd party download managers would bomb out?

    Cheers,
    Riaan
  6. #34
  7. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2925
    Originally Posted by R144N
    Thanks for making my life much easier with this post. Had sleeples nights thinking how to proceed...

    Works perfectly with default IE downloader.

    Is there any reason why DAP and other 3rd party download managers would bomb out?

    Cheers,
    Riaan
    hi Riaan and welcome to the forum!

    I fear I have no idea what's DAP, never heard if it.
  8. #35
  9. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Sep 2007
    Posts
    2
    Rep Power
    0
    Thanks Shadow Wizard...

    DAP = Download Accelorator Plus. It wasn't the script tho, it was a setting on my FTP server. Problem fixed...

    Thanks for a gr8 script...

    xR
  10. #36
  11. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2925
    no problem Riaan, glad you like the code and that you got your problem sorted.
  12. #37
  13. No Profile Picture
    Contributing User
    ASP Explorer (0 - 99 posts)

    Join Date
    Apr 2006
    Posts
    47
    Rep Power
    12
    Hello folks,

    This script helps alot especially when hiding the actual path.

    I implemented this script and it works fine but i notice that it replaces the space with a underscore when i downloaded a file.

    i.e.

    "help file.txt"

    it should be "help%20file.txt" but it is replaced with "help_file.txt"

    How do i maintain the same file name format?

    Thanks in advance

    Cheers!
  14. #38
  15. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2925
    my code is not replacing anything. it get file name and send that
    file, if exists, to the browser.

    post your exact code and how you're using it (i.e. how you call the code)
    and we'll try to debug this problem.
  16. #39
  17. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Nov 2007
    Posts
    26
    Rep Power
    0
    Originally Posted by degsy
    Check that the path is correct. If you are missing a trailing backslash then it can corrupt the script.
    This code is great regardless of my little problem. Thank you.


    My code looks exactly like yours except I use server.mappath (Therefore I removed the "Const"):
    Code:
    <% 
    Response.Buffer=True 
    
    'Constants
    FOLDER_PATH=Server.MapPath("DownLoadFiles\") 'full path to the secure folder
    Const adTypeBinary = 1
    Const adTypeText = 2
    Const chunkSize = 2048
    
    'global variables:
    Dim strFileName 'name of the file to be downloaded
    Dim blnForceDownload 'force the download or allow the file to be opened in the browser?
    
    'read file from querystring:
    strFileName=Request("file")
    
    'force download?
    blnForceDownload = (Request("force")="true")
    
    'execute the function if we got anything:
    If Len(strFileName)>0 Then
    	Call DownloadFile (strFileName, blnForceDownload)
    	Response.END
    End If
    
    Sub DownloadFile(strFileName, blnForceDownload)
    	'local variables:
    	Dim fso, objFile, strFilePath
    	Dim fileSize, blnBinary, strContentType
    	Dim objStream, strAllFile, iSz
    	Dim i
    	
    	'----------------------
    	'first step: verify the file exists
    	'----------------------
    	
    	'build file path:
    	strFilePath=FOLDER_PATH
    	' add backslash if needed:
    	If Right(strFilePath, 1)<>"\" Then strFilePath=strFilePath&"\"
    	strFilePath=strFilePath&strFileName
    	
    	'initialize file system object:
    	Set fso=Server.CreateObject("Scripting.FileSystemObject")
    	
    	'check that the file exists:
    	If Not(fso.FileExists(strFilePath)) Then
    		Set fso=Nothing
    		Err.Raise 20000, "Download Manager", "Fatal Error: file does not exist: "&strFilePath
    		Response.END
    	End If
    	
    	'----------------------
    	'second step: get file size.
    	'----------------------
    	Set objFile=fso.GetFile(strFilePath)
    	fileSize=objFile.Size
    	Set objFile=Nothing
    	
    	'----------------------
    	'third step: check whether file is binary or not and get content type of the file. (according to its extension)
    	'----------------------
    	blnBinary=GetContentType(strFileName, strContentType)
    	strAllFile=""
    	
    	'----------------------
    	'forth step: read the file contents.
    	'----------------------
    	'force download? if so, add proper header:
    	If blnForceDownload Then
    	    	Response.AddHeader "Content-Disposition", "attachment; filename="&strFileName
    	End If
    	If blnBinary Then
    		Set objStream=Server.CreateObject("ADODB.Stream")
    		
    		'Added to breakup chunk
    		Response.Buffer = False 
    		
    		'this might be long...
    	    	Server.ScriptTimeout = 30000
    		
    
    		
    		'----------------------
    		objStream.Open
    		objStream.Type = 1 'adTypeBinary
    		objStream.LoadFromFile strFilePath
    		
    		'Added to breakup chunk
    		iSz = objStream.Size
    		Response.AddHeader "Content-Length", iSz
    		Response.Charset = "UTF-8"
    		Response.ContentType = strContentType
    		For i = 1 To iSz \ chunkSize
    			If Not Response.IsClientConnected Then Exit For
    			Response.BinaryWrite objStream.Read(chunkSize)
    		Next 
    		If iSz Mod chunkSize > 0 Then 
    			If Response.IsClientConnected Then 
    				Response.BinaryWrite objStream.Read(iSz Mod chunkSize)
    			End If 
    		End If
      		objStream.Close
    		Set objStream = Nothing		
    		'--------------------------------------
    		'Commented out Original Code
    		'strAllFile=objStream.Read(fileSize)
    		'objStream.Close
    		'Set objStream = Nothing
    		'--------------------------------------
    	Else  
    		Set objFile=fso.OpenTextFile(strFilePath,1) 'forReading
    		If Not(objFile.AtEndOfStream) Then
    			strAllFile=objFile.ReadAll
    		End If
    		objFile.Close
    		Set objFile=Nothing
    		Response.Write(strAllFile)
    	End If
    	
    	'clean up:
    	Set fso=Nothing
    	Response.Flush
    	Response.END
    End Sub
    
    Function GetContentType(ByVal strName, ByRef ContentType)
    	'return whether binary or not, put type into second parameter
    	Dim strExtension
    	strExtension="."&GetExtension(strName)
    	Select Case strExtension
    		Case ".asf"
    			ContentType = "video/x-ms-asf"
    			GetContentType=True
    		Case ".avi"
    			ContentType = "video/avi"
    			GetContentType=True
    		Case ".doc"
    			ContentType = "application/msword"
    			GetContentType=True
    		Case ".zip"
    			ContentType = "application/zip"
    			GetContentType=True
    		Case ".xls"
    			ContentType = "application/vnd.ms-excel"
    			GetContentType=True
    		Case ".gif"
    			ContentType = "image/gif"
    			GetContentType=True
    		Case ".jpg", ".jpeg"
    			ContentType = "image/jpeg"
    			GetContentType=True
    		Case ".wav"
    			ContentType = "audio/wav"
    			GetContentType=True
    		Case ".mp3"
    			ContentType = "audio/mpeg3"
    			GetContentType=True
    		Case ".wma" 
    			ContentType = "audio/wma"
    			GetContentType=True
    		Case ".mpg", ".mpeg"
    			ContentType = "video/mpeg"
    			GetContentType=True
    		Case ".pdf"
    			ContentType = "application/pdf"
    			GetContentType=True
    		Case ".rtf"
    			ContentType = "application/rtf"
    			GetContentType=True
    		Case ".htm", ".html"
    			ContentType = "text/html"
    			GetContentType=False
    		Case ".asp"
    			ContentType = "text/asp"
    			GetContentType=False
    		Case ".txt"
    			ContentType = "text/plain"
    			GetContentType=False
    		Case Else
    			'Handle All Other Files
    			ContentType = "application/octet-stream"
    			GetContentType=True
    	End Select
    End Function
    
    Function GetExtension(strName)
    	Dim arrTmp
    	arrTmp=Split(strName, ".")
    	GetExtension=arrTmp(UBound(arrTmp))
    End Function
    %>
    I check the path everything seems ok.

    To test my code here:

    http://www.pranklin.com/testdownload.asp

    It downloads 2 excel files.

    Thank you
  18. #40
  19. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2925
    bazzapr, do you have problem with the code or did you give this
    as example of how to have the code with MapPath?
  20. #41
  21. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Nov 2007
    Posts
    26
    Rep Power
    0
    Sorry I thought I quoted a problem someone else had. My mistake.

    The problem is that when I download the files there names are always changed DownloadManager.xls but their actual names are test1.xls and test2.xls.

    Regards,
    Barry
  22. #42
  23. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2925
    try to force download. what happens?
  24. #43
  25. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Nov 2007
    Posts
    26
    Rep Power
    0
    Originally Posted by Shadow Wizard
    try to force download. what happens?
    Great thanks that worked.
  26. #44
  27. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2925
    Originally Posted by bazzapr
    Great thanks that worked.
    weird. I'll have to check this behavior when I'll have some time.
    in theory, when Force Download is false, the file should Open
    in the browser, without dialog box..
  28. #45
  29. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Oct 2007
    Posts
    2
    Rep Power
    0

    Download speed


    When downloading a mp3 (4.7MB) through the DownloadManager my max speed is about 5% (40kBps) of my total line max (900kBps). E.g.: mydomain.com/file=music.mp3

    And when downloading without the DownloadManager i get full speed. E.g.: mydomain.com/music.mp3

    Is there a download limit in the script? How can I get around this "limit"?

Similar Threads

  1. File Download problems
    By clboren in forum ASP Development
    Replies: 0
    Last Post: March 15th, 2005, 05:54 PM
  2. Issue downloading large files
    By Ceuphrasie in forum ASP Development
    Replies: 13
    Last Post: March 14th, 2005, 11:33 AM
  3. Download Two Files From One Button?
    By Currie in forum .NET Development
    Replies: 1
    Last Post: February 5th, 2005, 04:56 AM
  4. Downloading files
    By Zil in forum .NET Development
    Replies: 7
    Last Post: January 8th, 2005, 09:23 AM
  5. FTP download a number of files with same extension
    By otarboy in forum Visual Basic Programming
    Replies: 1
    Last Post: September 29th, 2004, 12:27 PM

IMN logo majestic logo threadwatch logo seochat tools logo