7 Replies - 1639 Views - Last Post: 17 March 2011 - 10:38 AM

#1 Dean_Grobler  Icon User is offline

  • D.I.C Regular

Reputation: 39
  • View blog
  • Posts: 390
  • Joined: 15-January 10

Download file feature using HTML or JavaScript

Posted 17 March 2011 - 12:58 AM

Hi again,

Looks like I'm on a roll posting stuff in this forum today..Anyways, I just quickly wanted to find out if it's possible
if one can use HTML or JS to add functionality in your webpage for a using to perhaps click a link to download files...?

I'm busy putting together a portfolio on my blog (on blogger) and want people to be able to download source code for projects I've worked on. I highly doubt that I'll be able to do this in HTML as I don't know any tags that would help with this.

Also I won't be able to use another technology such as PHP for this, as I said, it's on blogger, one can only use HTML and Javascript in your posts...

Any help would greatly be appreciated!

***********Edit**************
The file that will be downloadable will be a .zip folder...

This post has been edited by Dean_Grobler: 17 March 2011 - 01:01 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Download file feature using HTML or JavaScript

#2 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 2935
  • View blog
  • Posts: 7,685
  • Joined: 08-June 10

Re: Download file feature using HTML or JavaScript

Posted 17 March 2011 - 01:05 AM

just give a link to the zip file, as a browser usually doesn’t unzip these, they’re downloaded by default.
Was This Post Helpful? 0
  • +
  • -

#3 Dean_Grobler  Icon User is offline

  • D.I.C Regular

Reputation: 39
  • View blog
  • Posts: 390
  • Joined: 15-January 10

Re: Download file feature using HTML or JavaScript

Posted 17 March 2011 - 01:08 AM

View PostDormilich, on 17 March 2011 - 01:05 AM, said:

just give a link to the zip file, as a browser usually doesn’t unzip these, they’re downloaded by default.


Oh okay cool, the path in the link that I will be using, should this be an URL to some site where I have stored the .zip folder or can the path just consist of the path on my machine(like C:\Dean\My Documents\....etc) ?
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 2935
  • View blog
  • Posts: 7,685
  • Joined: 08-June 10

Re: Download file feature using HTML or JavaScript

Posted 17 March 2011 - 01:51 AM

it must be an URL on the webserver, otherwise (C:\…) the browser tries to open a local resource, which is unlikely to exist.
Was This Post Helpful? 1
  • +
  • -

#5 Dean_Grobler  Icon User is offline

  • D.I.C Regular

Reputation: 39
  • View blog
  • Posts: 390
  • Joined: 15-January 10

Re: Download file feature using HTML or JavaScript

Posted 17 March 2011 - 01:54 AM

Damn.. I don't have a webserver. You know of anysites that can help me with something like this? Like a free online storing or something like that?
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 2935
  • View blog
  • Posts: 7,685
  • Joined: 08-June 10

Re: Download file feature using HTML or JavaScript

Posted 17 March 2011 - 01:55 AM

doesn’t blogspot allow you to serve those files?
Was This Post Helpful? 0
  • +
  • -

#7 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 921
  • View blog
  • Posts: 6,456
  • Joined: 07-September 06

Re: Download file feature using HTML or JavaScript

Posted 17 March 2011 - 10:02 AM

If you wanted you could sign up for a microsoft skydrive which will get you 25GB online storage for free and you can share links to public files.
Was This Post Helpful? 1
  • +
  • -

#8 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3113
  • View blog
  • Posts: 4,675
  • Joined: 08-June 10

Re: Download file feature using HTML or JavaScript

Posted 17 March 2011 - 10:38 AM

Hey.

You may be able to use the Data URI scheme to include small files.

The idea is basically to encode the file data itself into the HTML file so that you don't have to download it separately. - It's mostly used for small images and such for the UI, but I can't see why a ZIP file couldn't be included.

You'd need to create a script on your end to Base64 encode the file data into the HTML, but that's simple enough to do. For example, this PHP code injects a "project.zip" file into a <a> tag.
<?php
$infile = "project.zip";
$encodedData = base64_encode(file_get_contents($infile));

echo <<<HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <title>My project's source code.</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <h1>My project's source code.</h1>
        <p>
            <a href="data:application/zip;base64,{$encodedData}">Click to download</a>
        </p>
    </body>
</html>
HTML;
?>


You could copy the output of that and save it as a .HTML file, then upload it to your server, where the file could be downloaded by clicking the link.

The only downside here is lack of proper browser support. This currently doesn't work in any version of Internet Explorer (not even 9 :() - Firefox also seems to assign it weird names, but renaming it to .zip makes it work fine. (I suppose it could be possible to add meta-data to the tag, but I haven't tried that out.) - Chrome and Opera handle this perfectly.

This post has been edited by Atli: 17 March 2011 - 10:39 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1