Hi,

I am hoping someone can help me.. I am trying to set out and ordering system for my wife's business.

At this stage I have a basic form that can upload multiple files to a sql database. Which i have working (not as i think it should, but working).

I have 2 things i want it to do:

  1. Form be abe to upload as many files as 12 but still upload if only 2 images are selected.
  2. Bea ble to rettrieve the files from the database easily in one go. At the moment to code below will allow me to view both file names on screen but only download 1 of them.

I am open to a better idea or someone pointing me in the direction of how to fix this or be able to compress all the uploaded files in to 1 zip folder and put that file in the databse instead of all the separate files.

I hope this is making sense, it is very late and i have been trying to get this to work for hrs.

<?
if(isset($_GET['id']))
{
// Details for webhost below:////////////
////////////////////////////////////////

$con = mysql_connect("localhost","user","pass");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }


mysql_select_db("salli_gifts", $con);

$id      = $_GET['id'];
$query   = "SELECT name, type, size, content FROM upload WHERE id = '$id'";
$result  = mysql_query($query) or die('Error, query failed');
list($name, $type, $size, $content) = mysql_fetch_array($result);

header("Content-Disposition: attachment; filename=$name");
header("Content-length: $size");
header("Content-type: $type");


}

?>
<?
if(isset($_GET['id']))
{
$con = mysql_connect("localhost","user","pass");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }


mysql_select_db("salli_gifts", $con);

$id      = $_GET['id'];
$query   = "SELECT name2, type2, size2, content2 FROM upload WHERE id = '$id'";
$result  = mysql_query($query) or die('Error, query failed');
list($name2, $type2, $size2, $content2) = mysql_fetch_array($result);

header("Content-Disposition: attachment; filename=$name2");
header("Content-length: $size2");
header("Content-type: $type2");
}
?>

<html>
<head>
<title>Download File From MySQL</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body,td,th {
	font-family: BankGothic Lt BT;
	font-size: 12px;
}
-->
</style></head>

<body>
<?
// Details for webhost below:////////////
////////////////////////////////////////

$con = mysql_connect("localhost","user","pass");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }


mysql_select_db("salli_gifts", $con);
$query = "SELECT COUNT(id) AS numrows FROM upload";
$result  = mysql_query($query) or die('Error, query failed');
$row     = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];

$query  = "SELECT id, name, name2 FROM upload";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result) == 0)
{
	echo "<br>";
	echo "<br>";
	echo "$numrows <b>Download(s)in our database</b>";
	echo "<br>";
	echo "<br>";
    echo "Database is empty <br>";
 }
else
{
	echo "<br>";
	echo "<br>";
	echo "$numrows <b>Download(s)in our database</b>";
	echo "<br>";
	echo "<br>";
    while(list($id, $name, $name2) = mysql_fetch_array($result))

{
?>
    <a href="download.php?id=<?=$id;?>"><?=$name;?></a> <br>
	<a href="download.php?id=<?=$id;?>"><?=$name2;?></a> <br>
	<?        
} } mysql_close($con); ?> </body> </html>

Your help is much apprecited. I hope this post is formatted properly this time.

Thanks.!!!

    I dont think you can download multiple files at once, you would have to have them download one at a time. Just because you cant stream mutiple files from one call, you'll have to make each individual request seperate.

    The next thing, if you are going to be downloading the file via header, seperate the download file from your HTML code, because the code will also stream down and corrupt your file.

    if it's just files you are downloading, you hdont have to set he header, just link them to the URL where the files are stored.

    YOu can upload muliple files at once, all you have to do is set your form up properly and access them via the $_FILES variable on the server.
    THen you can proccess the file and store the URL in the database

      Thanks for the response. It all sound good but i am so new at this. Do you know of any examples i can look at, what you said makes sense but i have no idea how to do it.

      Thanks again.

        Write a Reply...