Results 1 to 3 of 3

Thread: How to make it so you can download

  1. #1
    Join Date
    Aug 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to make it so you can download

    I just wanna know whats the code so that when you click a link it turns into a download


    Sorry if i posted this in wrong section kinda new

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Try putting the file in a zipfile.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by anti-hero
    I just wanna know whats the code so that when you click a link it turns into a download
    There is no code, as such, that causes a dialogue box to query, "Open or Save to disk?"

    When a browser makes a request for a resource, such as a HTML document or an image, the server (or cache) sends back that resource with a content type indicating what that resource is, and allowing the browser to decide how to handle it. When the browser encounters a content type that it doesn't recognise, or one that it hasn't been told to handle itself, it asks the user to download the data.

    So, one way to get this effect is to make the server send an unrecognised content type, or one that browsers should not attempt to handle. The latter, and preferred, is application/octet-stream which implies (generic) binary data. For instance, you could state that all files that map to the directory,

      http://www.example.com/downloads/

    should be served with application/octet-stream on an Apache server using:

    Code:
    <Location /downloads/>
      ForceType application/octet-stream
    </Location>
    A second approach uses a commonly implemented extension called content disposition. This was originally meant for use with MIME-encoded messages, but was added (unofficially) to HTTP. It allows you to mark a resource as a separate, attached resource, and suggest a download name for it. It is a HTTP header like Content-Type (discussed above), and must also be sent by the server. You could do a similar thing as in the example above:

    Code:
    <Location /downloads/>
      Header set Content-Disposition "attachment; filename=name"
    </Location>
    Unfortunately, some browsers (some versions of IE, in particular) don't react as they should. Using both of these methods in combination is the best approach, but it isn't guaranteed to work in all cases.

    To use the directives above, you need to modify the server configuration, which might not be possible. An alternative is to remove the Location directives (leaving just Header and ForceType) and place them in a .htaccess file (that is, dot-htaccess) in the directory in question. Be aware that the behaviour here will be slightly different. The Location directive works by matching URLs, whereas a .htaccess file works like the Directory directive which operates on the filesystem of the server; where the files are actually stored. This isn't necessarily the same thing as URLs don't need to map directly to a filesystem location.

    Mike

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
  •