Results 1 to 6 of 6

Thread: Forcing a file download

  1. #1
    Join Date
    Jan 2008
    Posts
    55
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Forcing a file download

    This subject was introduced in development support - I think I can migrate it to here....

    I want to be able to force a file download for an image file as opposed to it opening in a browser window.

    I'm tackling this from several directions and so far....

    configure an .htaccess file on linux servers. Works great with firefox, however IE still wants to view the file.

    Have a copy of the image zipped and in another directory. Definately works, however causes a lot of work if manually dealing with a lot of files and complicates things with the file upload if trying to automate the process... that is being looked at!

    Have it coded within the script that is referring to the file... trouble is it is an external script ... the basics are someone wants a file, they click on a link that takes them to a payment gateway - in this case it's a mobile phone service provider, once a text has been sent they are refered to the directory where that file is held.

    I have contacted the company to see if anything can be done there end, however in the meantime I have also come across this:

    http://support.microsoft.com/kb/q260519/

    hence the reason for this post!

    How To Raise a "File Download" Dialog Box for a Known MIME Type

    To apply the header dynamically, create an Active Server Pages (ASP) file that writes the document out to the browser. Use the Response.AddHeader method to add the content-disposition header. For example:

    Response.AddHeader "content-disposition","attachment; filename=fname.ext"

    Can this be added to the directory - like an .htaccess file to force a download for all the images in that directory, if so how?

    Finally,on running through Helm, there is a MIME types link which allows you to customise MIME types. Can I change this so that .jpg files are downloaded from the server for that particular domain? If that is the case I am assuming that all 'image' files embeded in the web pages would then have to be gifs and pngs otherwise it that was possible you'd get dialog boxes for those as well

  2. #2
    Join Date
    Apr 2006
    Location
    Amsterdam
    Posts
    352
    Thanks
    20
    Thanked 11 Times in 11 Posts

    Default

    Quote Originally Posted by UKFlyer View Post
    .. however in the meantime I have also come across this:

    http://support.microsoft.com/kb/q260519/

    hence the reason for this post!

    How To Raise a "File Download" Dialog Box for a Known MIME Type

    To apply the header dynamically, create an Active Server Pages (ASP) file that writes the document out to the browser. Use the Response.AddHeader method to add the content-disposition header. For example:

    Response.AddHeader "content-disposition","attachment; filename=fname.ext"

    Can this be added to the directory - like an .htaccess file to force a download for all the images in that directory, if so how?

    I never used it my self, but is seems fairly straight forward. You will need to create a ASP file using the code above and always use the ASP file to download the images. (do you have any asp coding skils?) Its diffrent from .htaccess though, call/open/access the ASP file to download an image.

    Quote Originally Posted by UKFlyer View Post
    Finally,on running through Helm, there is a MIME types link which allows you to customise MIME types. Can I change this so that .jpg files are downloaded from the server for that particular domain? If that is the case I am assuming that all 'image' files embeded in the web pages would then have to be gifs and pngs otherwise it that was possible you'd get dialog boxes for those as well
    I am not sure. I don't think it would work, becuase a file needs to be attachment in order to get it to work. Its not possbile to attachment files with the MIME type editor in helm.

  3. #3
    Join Date
    Mar 2005
    Location
    Isle of Man
    Posts
    1,261
    Thanks
    3
    Thanked 24 Times in 24 Posts

    Default

    [edit]humm.maybe I'm getting confused here. I shall hold my thought for a bit[/edit]
    Last edited by nick; 6th March 2008 at 12:33 PM. Reason: rethinking

  4. #4
    Join Date
    Apr 2006
    Location
    Amsterdam
    Posts
    352
    Thanks
    20
    Thanked 11 Times in 11 Posts

    Default

    From the top of my mind, not tested the code:
    <%
    Dim strImageFile
    strImageFile = Request.QueryString("filename")

    Function fcnAllowedExtensions(strFileName)
    strExt = Right(strFileName, 3)
    select case strExt
    case "jpg"
    strAllowed = true
    case "jpeg"
    strAllowed = true
    case Else
    strAllowed = false
    end select

    fcnAllowedExtensions = strAllowed
    End Function

    If fcnAllowedExtensions(strImageFile) = true Then
    Response.AddHeader "content-disposition","attachment; filename=" & strImageFile & ""
    Else
    Response.Write("File Extension Not Allowed")
    End If
    %>

  5. #5
    Join Date
    May 2007
    Location
    Eauze, France
    Posts
    175
    Thanks
    10
    Thanked 17 Times in 15 Posts

    Default

    Quote Originally Posted by Rappie View Post
    From the top of my mind, not tested the code:
    <%
    Dim strImageFile
    strImageFile = Request.QueryString("filename")

    Function fcnAllowedExtensions(strFileName)
    strExt = Right(strFileName, 3)
    select case strExt
    case "jpg"
    strAllowed = true
    case "jpeg"
    strAllowed = true
    case Else
    strAllowed = false
    end select

    fcnAllowedExtensions = strAllowed
    End Function

    If fcnAllowedExtensions(strImageFile) = true Then
    Response.AddHeader "content-disposition","attachment; filename=" & strImageFile & ""
    Else
    Response.Write("File Extension Not Allowed")
    End If
    %>
    I think that you need to change true and false to vbtrue & vbFalse. [Also "jpeg" can never be true dure to the Right(,3)

    David.

  6. The Following User Says Thank You to SKILLIT For This Useful Post:

    RFH Reseller: Rappie (6th March 2008)

  7. #6
    Join Date
    Jan 2008
    Posts
    55
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default All sorted

    OK thanks for that guys.

    According to the tech team from the mobile phone company there was a more advance version available which allowed me to install a PHP file on the site server which interacts with their server overcoming that problem. Configured the updated version, installed the file and all works....

    Job done!

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. I cann't download emails
    By HostCan in forum Technical Support
    Replies: 3
    Last Post: 23rd April 2007, 01:28 PM
  2. Secure download folder
    By s80wkr in forum ASP (VBScript)
    Replies: 2
    Last Post: 25th October 2006, 07:44 PM
  3. Webmail attachment download
    By Jaro in forum General Technical Support
    Replies: 11
    Last Post: 17th August 2006, 07:40 PM
  4. Download Manager
    By terraqueotenaz in forum Web Applications and Scripts
    Replies: 2
    Last Post: 6th July 2005, 05:59 AM

Bookmarks

Posting Permissions

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