Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,114 members, 7,814,913 topics. Date: Wednesday, 01 May 2024 at 11:09 PM

Help, How To Attach File Download - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Help, How To Attach File Download (890 Views)

Help!!! How To Add My Site To A Facebook Like Page / How To Attach Php,javascripts And Host A Website.www.sforeverconsult.com / How To Attach Large Files (2) (3) (4)

(1) (Reply) (Go Down)

Help, How To Attach File Download by zegmart: 2:55pm On Jan 13, 2009
Can somebody help . How can I add file download to my web page?


my mail: baseg2002@yahoo.com
Re: Help, How To Attach File Download by Nobody: 10:11pm On Jan 13, 2009
I think you should take a look at http://www.phpjunkyard.com/ - i hope it helps.
I downloaded one of the ones on junkyard and modified it a lil bit for my website - www.mwebng.net

But a simple one will be

download.php

<?php
$url=$_REQUEST['url'];


$filename="$url";
$dfile="./$url";

// 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,"."wink,1));

if( $filename == "" )
{
echo "<html><title>Download Area</title><body>ERROR: download file NOT SPECIFIED. USE dl.php?file=filepath</body></html>";
exit;
} elseif ( ! file_exists("$dfile"wink )
{
echo "<html><title>Download Area</title><body>ERROR: File not found. USE dl.php?file=filepath</body></html>";
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"wink; // required
header("Expires: 0"wink;
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"wink;
header("Cache-Control: private",false); // required for certain browsers
header("Content-Type: $ctype"wink;
// change, added quotes to allow spaces in filenames, by Rajkumar Singh
header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );
header("Content-Transfer-Encoding: binary"wink;
header("Content-Length: ".filesize($dfile));
readfile("$dfile"wink;
//exit();
?>



Usage: download.php?url=myprograme.zip

I suspect that one is easy to follow?
Re: Help, How To Attach File Download by Nobody: 10:15pm On Jan 13, 2009
Another simpler example will be:


<?php
$file = 'monkey.gif';

//$file=$_REQUEST['url'];

if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
?>
Re: Help, How To Attach File Download by teemy(m): 10:34pm On Jan 17, 2009
Try using open in a new window (_blank) type for the link. Hope it helps out. If you need more help such as security let me know. Also hope you have the file itself uploaded with your favourite FTP software.

(1) (Reply)

Urgent Help Pls: How Can I Put Up Google Adsense In My Smf? / Where In The World Is Omnipotens? / Cbn Governor Give ''intervention Fund'' To The Software Industry

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 19
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.