www.webdeveloper.com
Results 1 to 8 of 8

Thread: Downloading a local file...

  1. #1
    Join Date
    May 2005
    Posts
    502

    Downloading a local file...

    I have a website running off a windows server in a client's office. I need to allow a file on another, local computer to be downloaded off the website. How can I link to the file?

    At the moment I'm thinking the only way is to mount the directory containing the file onto one of the server's drives, and access it with a "../../../g:/somedirectory/file.txt"

    Any suggestions? I haven't got a clue

  2. #2
    Join Date
    Jun 2003
    Location
    Indiana, USA
    Posts
    1,138
    Why don't you just pull that file over to the web server itself?

    If you don't want to do this, you will probably need to setup an external ilp address for that pc and just link to the file with that ip.
    Chris.Martz.me
    Some things Man was never meant to know. For everything else, there's Google.

  3. #3
    Join Date
    May 2005
    Posts
    502
    Can't set up an external IP to that machine, its not going to be set up as a web server

    And I can't copy the file over as it gets updated every night

  4. #4
    Join Date
    Dec 2003
    Location
    England, UK
    Posts
    432
    if you need to send the file through the webserver from the other machine you could try something like this

    Code:
    <%
    
    filename = "d:\testfile.txt"
    sendfile filename
    
    
    
    function sendfile(filename)
    
    	dim oStream,oFso,oFile
    
    	set ofso = createobject("scripting.filesystemobject")
    
    	if ofso.fileexists(filename) then
    
    		set ofile = ofso.getfile(filename)
    
    		response.clear
    
    		Response.AddHeader "Content-Disposition", "attachment; filename=" & ofile.name
    		Response.AddHeader "Content-Length", ofile.size
    		Response.CharSet = "UTF-8"
    		Response.ContentType = "application/octet-stream"
    
    		set ofile = nothing
    
    		set oStream = createobject("adodb.stream")
    
    		oStream.open
    		oStream.type = 1
    
    		oStream.loadfromfile filename
    
    		response.binarywrite ostream.read
    
    		oStream.close
    
    	end if
    
    end function
    
    %>
    not sure whether you'll need to map the drive or not. depends whether an ado stream object can use a UNC path or not (which i've not tried).

    you might also want to change the headers being sent. at the moment it forces a download prompt to appear.

  5. #5
    Join Date
    May 2005
    Posts
    502
    Hi Russell

    I've set filename to be "\\serverB\path\somefile.txt" but the "if ofso.fileexists(filename)" test returns false.

    Does that mean that I can't use paths pointing to other servers on the network?

  6. #6
    Join Date
    Dec 2003
    Location
    England, UK
    Posts
    432
    yeah. that's what i meant by using a unc path. if you map the drive you should be ok though i think.

  7. #7
    Join Date
    May 2005
    Posts
    502
    Fantastic. If I map the drive though I won't need to use the above script?

  8. #8
    Join Date
    Dec 2003
    Location
    England, UK
    Posts
    432
    depends how you want it to work. if you're happy to just set up another virtual directory pointing to your mapped drive then you don't need the script. however if you don't want to set up another virtual directory (maybe to hide other files in there) then you can send the file from within your existing application with the script.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles