Welcome to Dream.In.Code
Getting Help is Easy!

Join 107,420 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,147 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



How to make things Downloadable

 
Reply to this topicStart new topic

How to make things Downloadable

abgorn
post 14 Jun, 2008 - 02:10 PM
Post #1


D.I.C Head

**
Joined: 5 Jun, 2008
Posts: 170


My Contributions


I was wondering could anyone help me find out how to make files that I've uploaded on my website downloadable e.g zip files, images, etc
User is offlineProfile CardPM

Go to the top of the page


BetaWar
post 14 Jun, 2008 - 02:14 PM
Post #2


#include <soul.h>

Group Icon
Joined: 7 Sep, 2006
Posts: 1,107



Thanked 37 times

Dream Kudos: 675
My Contributions


Well, assuming that you are able to use php on your server (many free hosts don't allow this) you could use this script:

CODE
<?php
function force_download ($data, $name, $mimetype='', $filesize=false) {
    // File size not set?
    if ($filesize == false OR !is_numeric($filesize)) {
        $filesize = strlen($data);
    }

    // Mimetype not set?
    if (empty($mimetype)) {
        $mimetype = 'application/octet-stream';
    }

    // Make sure there's not anything else left
    ob_clean_all();

    // Start sending headers
    header("Pragma: public"); // required
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: private",false); // required for certain browsers
    header("Content-Transfer-Encoding: binary");
    header("Content-Type: " . $mimetype);
    header("Content-Length: " . $filesize);
    header("Content-Disposition: attachment; filename=\"" . $name . "\";" );

    // Send data
    echo $data;
    die();
}

function ob_clean_all () {
    $ob_active = ob_get_length () !== false;
    while($ob_active) {
        ob_end_clean();
        $ob_active = ob_get_length () !== false;
    }

    return true;
}
?>

http://www.phpit.net/code/force-download/
User is online!Profile CardPM

Go to the top of the page

abgorn
post 14 Jun, 2008 - 02:18 PM
Post #3


D.I.C Head

**
Joined: 5 Jun, 2008
Posts: 170


My Contributions


Is there a HTML way to do it?
User is offlineProfile CardPM

Go to the top of the page

BetaWar
post 14 Jun, 2008 - 02:41 PM
Post #4


#include <soul.h>

Group Icon
Joined: 7 Sep, 2006
Posts: 1,107



Thanked 37 times

Dream Kudos: 675
My Contributions


Right click and select "Save Target As" Sadly, I don't know of any way to do it with HTML. But if you wanted you could zip all your files that you want people to be able to download, that will make the download window popup when the click them (zipped files do it automatically).
User is online!Profile CardPM

Go to the top of the page

no2pencil
post 14 Jun, 2008 - 11:12 PM
Post #5


Wet D.I.C.

Group Icon
Joined: 10 May, 2007
Posts: 4,823



Thanked 25 times

Dream Kudos: 2325

Expert In: Goofing Off

My Contributions


QUOTE(abgorn @ 14 Jun, 2008 - 05:18 PM) *

Is there a HTML way to do it?

It's going to depend on the browser & OS settings. If the OS has a program associated with .zip, then the browser will ask if you want to open it with (option programs) or save it.

In short, you are basically offering the file & the user / viewer will decide what they want to do with it. You can't force feed them the file & what they will do with it.
User is online!Profile CardPM

Go to the top of the page

gabehabe
post 15 Jun, 2008 - 08:00 AM
Post #6


T3H R0XX0R!

Group Icon
Joined: 6 Feb, 2008
Posts: 2,258



Thanked 44 times

Dream Kudos: 1450

Expert In: C, C++

My Contributions


The simplest way to do it is to upload it as a zip, and then simply link to it, like so:
CODE
<a href="http://www.mysite.com/files/this_thing_i_made.zip">download this thing I made</a>


This post has been edited by gabehabe: 15 Jun, 2008 - 08:01 AM
User is offlineProfile CardPM

Go to the top of the page

itdemo
post 21 Jun, 2008 - 02:19 PM
Post #7


New D.I.C Head

*
Joined: 16 May, 2008
Posts: 44


My Contributions


How exactly do you use that php code in a web site?
User is offlineProfile CardPM

Go to the top of the page

biggles2008
post 21 Jun, 2008 - 04:10 PM
Post #8


D.I.C Addict

Group Icon
Joined: 5 Mar, 2008
Posts: 513



Thanked 1 times

Dream Kudos: 150
My Contributions


Upload, get the entire url ::: http://www.whatever.com/downloadfilename..exe

make sure u get the .exe, .zip, .rar and link to that need example?

CODE
http://ftp.blizzard.com/pub/WoW/other/InterfaceAddOnKit_Win.zip
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 8/28/08 08:12PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month