CChard
09-08-2002, 12:40 AM
How do you get PHP to start a download of a file (lets say a .zip)?
Here is my file:
<?php
include("functions.php");
if (!db_connect())
{
echo "Error: Could not connect to database. Please Contact Admin";
exit;
}
$result = mysql_query("select * from files WHERE id='$id' AND status='0'");
$row = mysql_fetch_array($result);
if(mysql_num_rows($result)==0)
{
echo "Error: Could not find file in database. Please Contact Admin";
exit;
}
$file = stripslashes($row['url']);
$downloads = $row['downloads']+1;
$fp = fopen($file, "r");
if(!fp)
{
echo "Error: Could not download file. Please Contact Admin";
exit;
}
else
{
$query = "update files set downloads='".$downloads."' where id='".$id."'";
$result = mysql_query($query);
echo "You may close this window.";
fclose($fp);
exit;
}
?>
The program finds the URL (Ex: http://www.atlanticrail.com/files/ac0001.zip) and then I need it to start a download.
I don't get any errors, just the "You may close this window" message. Meaning it opened the file.
Here is my file:
<?php
include("functions.php");
if (!db_connect())
{
echo "Error: Could not connect to database. Please Contact Admin";
exit;
}
$result = mysql_query("select * from files WHERE id='$id' AND status='0'");
$row = mysql_fetch_array($result);
if(mysql_num_rows($result)==0)
{
echo "Error: Could not find file in database. Please Contact Admin";
exit;
}
$file = stripslashes($row['url']);
$downloads = $row['downloads']+1;
$fp = fopen($file, "r");
if(!fp)
{
echo "Error: Could not download file. Please Contact Admin";
exit;
}
else
{
$query = "update files set downloads='".$downloads."' where id='".$id."'";
$result = mysql_query($query);
echo "You may close this window.";
fclose($fp);
exit;
}
?>
The program finds the URL (Ex: http://www.atlanticrail.com/files/ac0001.zip) and then I need it to start a download.
I don't get any errors, just the "You may close this window" message. Meaning it opened the file.
