Creating a download link

This is a discussion on "Creating a download link" within the Starting Out section. This forum, and the thread "Creating a download link are both part of the Design Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Design Your Website > Starting Out

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old May 29th, 2007, 17:55
Reputable Member
Join Date: Apr 2007
Location: Ireland
Age: 15
Posts: 332
Thanks: 0
Thanked 0 Times in 0 Posts
Creating a download link

Hello.

I was wondering how you create a download link. For example if someone wanted to download a (X)HTML and CSS file that was zipped up, how would I code this.

Thanks,
Padraig.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old May 29th, 2007, 18:15
Elite Veteran
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Creating a download link

hmmm ... a simple link would do?!

Code: Select all
<a href="something.zip">some code in zip</a>
or maybe I'm not understanding the question!?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old May 29th, 2007, 18:24
Reputable Member
Join Date: Apr 2007
Location: Ireland
Age: 15
Posts: 332
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Creating a download link

That worked for me.

Thanks Karinne!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old May 29th, 2007, 22:17
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Creating a download link

If you don't want to zip it, you can force a browser to download a file using PHP (ie, like an HTML page that a browser would normally try to render).
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old May 29th, 2007, 22:31
Reputable Member
Join Date: Apr 2007
Location: Ireland
Age: 15
Posts: 332
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Creating a download link

Quote:
Originally Posted by Ryan Fait View Post
If you don't want to zip it, you can force a browser to download a file using PHP (ie, like an HTML page that a browser would normally try to render).
Do you know where I can find any useful tutorials that explains how to do this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old May 29th, 2007, 22:35
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Creating a download link

PHP: Select all

<?php

$f 
fopen("file.html""rb"); // path to file on server
$content_len = (int) filesize("file.html"); // path to file on server
$content_file fread($f$content_len);
fclose($f);

$output_file 'file.html'// the name of the file when downloaded

@ob_end_clean();
@
ini_set('zlib.output_compression''Off');
header('Pragma: public');

header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: pre-check=0, post-check=0, max-age=0');
header('Cache-Control: private');
header('Content-Transfer-Encoding: none');
header('Content-Type: application/octetstream; name="'.$output_file.'"');
header('Content-Type: application/octet-stream; name="'.$output_file.'"');
header('Content-Disposition: inline; filename="'.$output_file.'"');
header("Content-length: $content_len");

echo 
$content_file;
exit();

?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old May 29th, 2007, 22:47
Reputable Member
Join Date: Apr 2007
Location: Ireland
Age: 15
Posts: 332
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Creating a download link

Thanks a lot for that, Ryan!

I will try and learn some php soon.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old May 29th, 2007, 22:51
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Creating a download link

No problem. To use that script, put it in an empty text file with the extension .php. If you link to that file in a browser, it will download whatever file is referenced in the first couple of lines.

Just be careful with it, though. Don't leave it open ended where someone can choose a file to download anywhere on your server. That PHP script can access anything on your server, regardless of whether it's in a password protected directory or out of your root directory.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old May 29th, 2007, 22:55
Reputable Member
Join Date: Apr 2007
Location: Ireland
Age: 15
Posts: 332
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Creating a download link

I'll definetly have a look at some php tutorials before trying something like this. I'll save that script to my computer in the mean time. Thanks again for the help and the script.

Pádraig.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
download, how to, link

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Download button - to download a PDF file attila001122 Web Page Design 4 Aug 15th, 2008 11:44
order confirmation email download link Aaron1988 PHP Forum 0 Sep 25th, 2006 20:03
Need help creating live web page changes when user clicks a link dannyboy Other Programming Languages 2 Feb 5th, 2006 11:43
creating a link to an ftp web site wat55up74 Web Page Design 2 Feb 1st, 2006 04:31


All times are GMT. The time now is 16:14.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42