Log in

View Full Version : Download File from WEB Site



roger38
06-22-2006, 08:28 AM
Could someone give me the code for downloading a file from my web site without using Active X Code. Thanks

BLiZZaRD
06-22-2006, 10:56 AM
Depends on the file type. For example, if you make a .zip file it will prompt the visitor to download once they browse to the file name...

or you can try something like this (untested):



<? php
function force_download($file)
{
$dir = "../log/exports/";
if ((isset($file))&&(file_exists($dir.$file))) {
header("Content-type: application/force-download");
header('Content-Disposition: inline; filename="' . $dir.$file . '"');
header("Content-Transfer-Encoding: Binary");
header("Content-length: ".filesize($dir.$file));
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $file . '"');
readfile("$dir$file");
} else {
echo "No file selected";
} //end if

}//end function
?>


orrrrr... take a look here: http://elouai.com/force-download.php

However, I don't think any of these methods are completely cross browser compatable.

Twey
06-22-2006, 01:02 PM
} //end if

}//end function And that, folks, is how not to comment code. :)

The idea is to explain bits that might not make sense, not to point out the blatantly obvious and leave the rest undocumented. :p

roger38: How files are handled is entirely up to the user. The best you can do is stick it in a ZIP archive, but even that won't necessarily cause the effect you want, if the user has their browser set up otherwise.

BLiZZaRD
06-22-2006, 04:46 PM
And that, folks, is how not to comment code. :)

The idea is to explain bits that might not make sense, not to point out the blatantly obvious and leave the rest undocumented. :p



LOL I said untested, I didn't say I wrote it... You know I couldn't do that... yet... I am still on page 3 of the W3 school, LMAO!

Twey
06-22-2006, 04:52 PM
I said untested, I didn't say I wrote itHahaha, fair enough :p