Page 1 of 1

Download File ???

Posted: Fri Nov 14, 2003 2:20 pm
by mudkicker
I need a File download script which will download the file i point with the URL coming from database.

Code: Select all

<?php

require("db.php");
$dp = new Db;
$dupd = @mysql_query("UPDATE downs SET downds=downds+1 WHERE downid=".$_GET['id']); // Counting
$dp->Close();
// Here it should be these code to download files.

?>
i get the url with $_GET['url'] variable. but i couldn't find how to make a download script???

thanks,
have a nice day. :?:

Posted: Fri Nov 14, 2003 2:28 pm
by JPlush76
here is some code I use for my downloading scripts
fpassthru is the key function here, you can read more about it on php.net

Code: Select all

<?php

	$filename = "data.txt";

	
	header("Content-type: application/octet-stream");
	header("Content-Length: ".filesize($filename));
	header("Content-Disposition: attachment; filename=$filename");
	

	$fp2 = fopen($filename, 'rb');
	fpassthru($fp2);
	@fclose($fp2);

?>

Posted: Fri Nov 14, 2003 3:58 pm
by mudkicker
thank..
so let me ask one more question...

with this can i make all filetypes like .zip .tar.gz .exe .msi download or should i add more codes too?

Posted: Fri Nov 14, 2003 4:15 pm
by JPlush76
yea you can download any kinda file you want :)

Posted: Fri Nov 14, 2003 5:50 pm
by mudkicker
this doesnt work...
it downloads the php file which processes the downloading.

Posted: Mon Nov 17, 2003 1:34 pm
by mudkicker

Code: Select all

<?
ob_start();
$filename = $_GET['url'];
$saveas = basename($filename);
    header("Content-Disposition: attachment; filename=".$saveas); 
    header("Content-Type: application/octet-stream"); 
    header("Content-Length: ".filesize($filename)); 
    readfile($filename); 
$dupd = @mysql_query("UPDATE downs SET downds=downds+1 WHERE downid=".$_GET['id']);
ob_end_flush();
?>
WHAT THE HELL IS WRONG WITH THIS FILE??? :evil: :evil: :evil:

I'm getting really sick, people...
with GET method i take the file url...
but it doesnt prompt download window :(