Download File ???

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Download File ???

Post 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. :?:
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post 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);

?>
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post 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?
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post by JPlush76 »

yea you can download any kinda file you want :)
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

this doesnt work...
it downloads the php file which processes the downloading.
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post 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 :(
Post Reply