Page 1 of 1

get .zip files from an mysql

Posted: Tue Sep 30, 2003 10:01 am
by Bonta_SWE
HI.
I have a site that i can upload .zip .rar files to an mysql. This files are counter-strike maps and i want visitors to download them. But how do i print them out ?
I have no idea to do that. I have looked around for a vile now and cant finde how to..
------------------------------------------------------------
Here are the files.sql
CREATE TABLE files (
id int(10) unsigned NOT NULL auto_increment,
name varchar(80) default 'None Given',
file_desc varchar(200) default NULL,
file_type varchar(60) default NULL,
file_size int(10) unsigned default NULL,
file_data blob,
downloads int(10) unsigned NOT NULL default '0',
PRIMARY KEY (id)
) TYPE=MyISAM;
--------------------------------------------------------------

When a visitor download them, the file should be saved with the name i uploaded it with.

Posted: Tue Sep 30, 2003 10:05 am
by Bonta_SWE
i forgot, i have one script that put them out, but not the way i want it to.

Here are the code for the script
<?php
##Change these lines to represent your actual database connect information.
@MYSQL_CONNECT("localhost","xxxxxx","xxxxxx");
@mysql_select_db("xxxxxx");
$self=$_SERVER['PHP_SELF'];
if (isset($_GET['id']))
{
$id=$_GET['id'];

$query = "select file_data, id,name,file_type,file_size,downloads from files where id='$id'";
@$result = MYSQL_QUERY($query);
$row=mysql_fetch_array($result);
$type = $row["file_type"];
$name= $row["name"];
$size= $row["file_size"];
$id= $row["id"];
$data= urldecode($row["file_data"]);
$downloads=$row["downloads"];
header("Content-type: $file_type");
header("Content-length: $size");
header("Content-Disposition: attachment; filename=$name");
header("Content-Description: PHP Generated Data");
echo $data;
$query = "update files SET downloads=downloads+1 WHERE id='$id' LIMIT 1";
@mysql_query($query);
die;
}
else{


$query = "select id,name,file_type,file_size,downloads from files";
$result = MYSQL_QUERY($query) or die("Can't execute!".mysql_error());
$table="<table summary=files border=1 cellpadding=2 cellspacing=2 bordercolor=#FFFFFF>"
."<tr bordercolor=#000000 bgcolor=#4C81A5><td>File name</td><td>Size</td><td>Download</td><td>Downloads</tr>";
while($row=mysql_fetch_array($result) )
{
$type = $row["file_type"];
$name= $row["name"];
$size= $row["file_size"];
$id= $row["id"];
$downloads=$row["downloads"];
$table .="<tr bordercolor=#000000><td>$name</td><td>$size</td><td><a href=$self?id=$id>Download </a><td>$downloads</td></td>";
}

}
?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Welcome to our Download Center!</title>
</head>
<body>
<?echo $table?>
</center>
</body>
</html>
This script generate a <table> and i dont want it to do that, becouse my site gets all srewd up.
Then i want every time a visitor downloaded a map, it should autoupdate "Downloads"

Posted: Tue Sep 30, 2003 3:52 pm
by Cruzado_Mainfrm
first, move the @ in @$result = MYSQL_QUERY($query); to $result = @MYSQL_QUERY($query); <-- that is not part of the problem

to get the file just do this:
//connect
//get the blob content in a variable like this:
$blob = mysql_result($resource,0,"filedata");
header("Content-type: application/zip");
echo $blob;