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
mudkicker
Forum Contributor
Posts: 479 Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:
Post
by mudkicker » Fri Nov 14, 2003 2:20 pm
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 » Fri Nov 14, 2003 2:28 pm
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);
?>
mudkicker
Forum Contributor
Posts: 479 Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:
Post
by mudkicker » Fri Nov 14, 2003 3:58 pm
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 » Fri Nov 14, 2003 4:15 pm
yea you can download any kinda file you want
mudkicker
Forum Contributor
Posts: 479 Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:
Post
by mudkicker » Fri Nov 14, 2003 5:50 pm
this doesnt work...
it downloads the php file which processes the downloading.
mudkicker
Forum Contributor
Posts: 479 Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:
Post
by mudkicker » Mon Nov 17, 2003 1:34 pm
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???
I'm getting really sick, people...
with GET method i take the file url...
but it doesnt prompt download window