There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer black screen blue screen boot bsod computer connection crash css dell display driver drivers email error excel explorer firefox firefox 3 game hard drive internet internet explorer itunes laptop linux malware network networking outlook outlook 2003 outlook express partition password printer problem ram router security slow software sound trojan usb video virus vista windows windows xp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Solved: Need download script !


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
tjamnz's Avatar
Computer Specs
Senior Member with 686 posts.
 
Join Date: Jun 2004
Location: Seattle
Experience: Intermediate
21-Feb-2007, 08:32 PM #1
Solved: Need simple "download 1 file" from webpage script !
Trying to make a link on my webpage, where ppl can download a word doc or pdf file...

Is there a simple html script for this (for transferring the file)? Much thanks for any info or scripts I can copy/paste and edit.

I have a paid hosting accnt. with multi-scripting support if necessary

l8
__________________
Tj

Dell Inspiron B130 notebook XP Professional
Acer T180 Desktop Vista Home Premium
Canon PowerShot A630 8MP
Canon Pixma MP160

MCP 70-270, 70-271

Last edited by tjamnz : 21-Feb-2007 08:48 PM. Reason: update
tjamnz's Avatar
Computer Specs
Senior Member with 686 posts.
 
Join Date: Jun 2004
Location: Seattle
Experience: Intermediate
21-Feb-2007, 10:06 PM #2
easy enough
Quote:
Originally Posted by tjamnz
Trying to make a link on my webpage, where ppl can download a word doc or pdf file...

Is there a simple html script for this (for transferring the file)? Much thanks for any info or scripts I can copy/paste and edit.

I have a paid hosting accnt. with multi-scripting support if necessary

l8
either http or ftp <a href="download.zip">click to download my file</a>

got it
namenotfound's Avatar
Computer Specs
Distinguished Member with 2,197 posts.
 
Join Date: Apr 2005
Location: New York
Experience: I know what I know, I am
21-Feb-2007, 10:10 PM #3
A file doesn't have to be zipped up to download when clicked. You can set it up in .htaccess or server-side language of your choice, to "force download" any file.
tjamnz's Avatar
Computer Specs
Senior Member with 686 posts.
 
Join Date: Jun 2004
Location: Seattle
Experience: Intermediate
21-Feb-2007, 10:24 PM #4
yeah.. ok,

Im not familar with that procedure, so for now i'll just stick to the <a href... (function)

Ive looked for a few tutes on this but so far no luck.
namenotfound's Avatar
Computer Specs
Distinguished Member with 2,197 posts.
 
Join Date: Apr 2005
Location: New York
Experience: I know what I know, I am
22-Feb-2007, 12:06 AM #5
If your host supports PHP you can use this script. I found it using Google and it works pretty well.

PHP Code:
<?php

$filename 
$_GET['file'];

// required for IE, otherwise Content-disposition is ignored
if(ini_get('zlib.output_compression'))
  
ini_set('zlib.output_compression''Off');

// addition by Jorg Weske
$file_extension strtolower(substr(strrchr($filename,"."),1));

if( 
$filename == "" 
{
  echo 
"<html><title>eLouai's Download Script</title><body>ERROR: download file NOT SPECIFIED. USE force-download.php?file=filepath</body></html>";
  exit;
} elseif ( ! 
file_exists$filename ) ) 
{
  echo 
"ERROR: File not found.";
  exit;
};
switch( 
$file_extension )
{
  case 
"pdf"$ctype="application/pdf"; break;
  case 
"exe"$ctype="application/octet-stream"; break;
  case 
"zip"$ctype="application/zip"; break;
  case 
"doc"$ctype="application/msword"; break;
  case 
"xls"$ctype="application/vnd.ms-excel"; break;
  case 
"ppt"$ctype="application/vnd.ms-powerpoint"; break;
  case 
"gif"$ctype="image/gif"; break;
  case 
"png"$ctype="image/png"; break;
  case 
"jpeg":
  case 
"jpg"$ctype="image/jpg"; break;
  default: 
$ctype="application/force-download";
}
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-Type: $ctype");
// change, added quotes to allow spaces in filenames, by Rajkumar Singh
header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));
readfile("$filename");
exit();

?>
name it as force-download.php

Then link to files like this:

Code:
<a href="http://yoursite.com/force-download.php?file=somefile.doc">Download a Word file</a>

http://elouai.com/force-download.php
tjamnz's Avatar
Computer Specs
Senior Member with 686 posts.
 
Join Date: Jun 2004
Location: Seattle
Experience: Intermediate
22-Feb-2007, 12:28 AM #6
Thank you for the php-file-download-script
great script

you rock!
namenotfound's Avatar
Computer Specs
Distinguished Member with 2,197 posts.
 
Join Date: Apr 2005
Location: New York
Experience: I know what I know, I am
22-Feb-2007, 12:38 AM #7
Glad I could help
tjamnz's Avatar
Computer Specs
Senior Member with 686 posts.
 
Join Date: Jun 2004
Location: Seattle
Experience: Intermediate
22-Feb-2007, 12:58 AM #8
link
Yeah,, thanks again..

I tried to click you link

$1 per 10x10 pixel ad space

link's broken.. just in case ...
namenotfound's Avatar
Computer Specs
Distinguished Member with 2,197 posts.
 
Join Date: Apr 2005
Location: New York
Experience: I know what I know, I am
22-Feb-2007, 01:07 AM #9
Yeah my host was having problems and randomly deleted a couple of sites, and mine was one of them

I think I'm gonna change my signature to something else...
tjamnz's Avatar
Computer Specs
Senior Member with 686 posts.
 
Join Date: Jun 2004
Location: Seattle
Experience: Intermediate
22-Feb-2007, 01:26 AM #10
sorry to hear that, must be frustrating to say the least. those backups will sure come in handy!
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 12:24 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.