Hope it helps . . .
<? //put this above the header info of your HTML
if(isset($_GET['id']))
{
//you will need to add name, type, size, path to your SQL table and make sure id is UI
$id = $_GET['id'];
$query = "SELECT name, type, size, path FROM upload WHERE id = '$id'";
$result = mysql_query($query) or die('Error, query failed');
list($name, $type, $size, $filePath) = mysql_fetch_array($result);
header("Content-Disposition: attachment; filename=$name");
header("Content-length: $size");
header("Content-type: $type");
readfile($filePath);
exit;
}
?>
<html>
<head>
<title>Upload PDFs to Field Controls Areas</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<style type="text/css">
<!--
.box {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
border: 1px solid #000000;
}
-->
</style>
<link href="../NewIndexStyle.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#4682B4">
<table width="720" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center" valign="top" bgcolor="#FFFFFF"><table width="720" border="0" align="center" cellpadding="4" cellspacing="0">
<tr>
<td height="29" align="center" valign="top"><h3>Field Controls .PDF Upload For New Documents Only</h3></td>
</tr>
</table>
<p>
</p>
<p>
<?
//name this file for the form
$this_file = 'fchupload.php';
//set an upload directory make sure it is writable
$uploadDir = '../pdfs/';
$bid = $_POST['bid'];
if(isset($_POST['upload']))
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$filePath = $uploadDir . $fileName;
$result = move_uploaded_file($tmpName, $filePath);
if (!$result) {
echo "Error uploading file";
exit;
}
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
}
//post the form data change to your needs
$formnumber = $POST['formnumber'] ;
$quantity = $POST['quantity'] ;
$section = $POST['section'] ;
${'section'.$section} = "checked=\"checked\"" ;
$linktitle = $_POST['linktitle'] ;
$category = $POST['category'] ;
${'category'.$category} = "selected=\"selected\"" ;
$query = "INSERT INTO upload (formnumber, quantity, section, linktitle, category, name, size, type, path ) ".
"VALUES ('$formnumber', '$quantity', '$section', '$linktitle', '$category', '$fileName', '$fileSize', '$fileType', '$filePath')";
mysql_query($query) or die('Error, query failed : ' . mysql_error());
echo "<br><center><h3>File Uploaded</strong></h3><br>";
}
echo "<form action=\"$this_file\" method=\"post\" enctype=\"multipart/form-data\" name=\"uploadform\">
<table width=\"350\" border=\"0\" align=\"center\" cellpadding=\"8\" cellspacing=\"1\" class=\"box\">
<tr>
<td align=\"center\" valign=\"top\">
<p>Browse to find the .PDF file you would like to upload:</p>
<p>
<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"5000000\">
<input name=\"userfile\" type=\"file\" class=\"box\" id=\"userfile\">
</p></td>
</tr>
<tr><td align=\"left\" valign=\"top\">Enter the Form Number of the document. <em>NA for no number</em><BR /><input name=\"formnumber\" type=\"text\" size=\"50\"></td></tr>
<tr><td align=\"left\" valign=\"top\">Enter the Pack Quantity for Literature. <em>NA if not literature section</em><BR /><input name=\"quantity\" type=\"text\" size=\"50\"></td></tr>
<tr><td align=\"left\" valign=\"top\">Enter the name you would like displayed in the menu.<BR /><input name=\"linktitle\" type=\"text\" size=\"50\"></td></tr>"; ?>
<tr><td align="center" valign="top"> Enter the Category the file should be associated with.<BR />
<select name="category">
<option selected>Select Category if Instruction Manual</option>
<option value="CONDENSATE PUMPS">CONDENSATE PUMPS</option>
<option value="CLEARWAVE™ WATER CONDITIONERS">CLEARWAVE™ WATER CONDITIONERS</option>
<option value="COMBUSTION AIR & MAKE-UP AIR SYSTEMS">COMBUSTION AIR & MAKE-UP AIR SYSTEMS</option>
<option value="EVENMIST™ HUMIDIFIERS">EVENMIST™ HUMIDIFIERS</option>
<option value="BAROMETRIC DRAFT CONTROLS">BAROMETRIC DRAFT CONTROLS</option>
<option value="Type RC">Type RC</option>
<option value="Type M">Type M</option>
<option value="Type MG1">Type MG1</option>
<option value="Draft Regulators">Draft Regulators</option>
<option value="Black Tee-Joint">Black Tee-Joint</option>
<option value="Type M + MG2">Type M + MG2</option>
<option value="ADA-1 Automatic Damper Adapter">ADA-1 Automatic Damper Adapter</option>
<option value="POWER VENTERS">POWER VENTERS</option>
<option value="Vent Hoods - for use with PV style power venters and other sidewall applications">Vent Hoods - for use with PV style power venters and other sidewall applications</option>
<option value="SWG Power Venters">SWG Power Venters</option>
<option value="Gas Furnace Kits">Gas Furnace Kits</option>
<option value="SWG Replacement Motor Kits and Accessories">SWG Replacement Motor Kits and Accessories</option>
<option value="CONTROL KITS">CONTROL KITS</option>
<option value="Gas - 30MV">Gas - 30MV</option>
<option value="Gas-24 V">Gas-24 V</option>
<option value="Gas-750MV">Gas-750MV</option>
<option value="Gas Furnace or Boiler & Water Heater">Gas Furnace or Boiler & Water Heater</option>
<option value="Oil - All Systems">Oil - All Systems</option>
<option value="DRAFT INDUCERS">DRAFT INDUCERS</option>
<option value="SAFETY SWITCHES">SAFETY SWITCHES</option>
<option value="STAR KAP® CHIMNEY CAPS">STAR KAP® CHIMNEY CAPS</option>
<option value="EVENAIR® AIR BOOSTERS">EVENAIR® AIR BOOSTERS</option>
<option value="GAS VENT DAMPERS">GAS VENT DAMPERS</option>
<option value="UV-AIRE™ AIR PURIFIERS">UV-AIRE™ AIR PURIFIERS</option>
<option value="WATER SENTRY PRO™">WATER SENTRY PRO™</option>
<option value="ACCESSORIES">ACCESSORIES</option>
<option value="MISCELLANEOUS">MISCELLANEOUS</option>
</select>
<center><p>OR</p></center>
<select name="category">
<option selected>Select Category if Wiring Diagrams</option>
<option value="For SWG Power Venter or DI Draft Inducer">For SWG Power Venter or DI Draft Inducer</option>
<option value="For CAS Units">For CAS Units</option>
<option value="Misc. Wiring Diagrams">Misc. Wiring Diagrams</option>
</select>
<BR />
</td></tr>
<tr>
<? echo " <td align=\"center\" valign=\"top\"> <p>Select which section to display the
file in:<br /><br />
<input type=\"radio\" name=\"section\" value=\"instructions\"
print($section_instructions);>Instructions
<input type=\"radio\" name=\"section\" value=\"wiring\"
print($section_wiring);>Wiring Diagrams <br />
<input type=\"radio\" name=\"section\" value=\"bulletins\"
print($section_bulletins);>Tech Bulletins
<input type=\"radio\" name=\"section\" value=\"literature\"
print($section_literature);>Literature
</p></td>
</tr>
<tr>
<td align=\"center\" valign=\"top\">
<p>
<input name=\"upload\" type=\"submit\" class=\"box\" id=\"upload\" value=\" Upload \">
</p></td>";
echo "
</tr>
</table>
</form>
</p>
<p> </p>
<hr>
<table width=\"720\" border=\"0\" align=\"center\" cellpadding=\"4\" cellspacing=\"0\">
<!--// anything below here shows the result of the upload and places a link to an edit page you can change this to display a link to the MP3 file or remove it all together //-->
<td align=\"center\" valign=\"top\"><p><strong>Current Instruction Manuals:</strong></center></strong></p>
<p> ";
$query = "SELECT id, name, linktitle FROM upload WHERE section = 'instructions'";
$result = mysql_query($query) or die('Error, query failed: ' . mysql_error());
if(mysql_num_rows($result) == 0)
{
echo "Database is empty <br>";
}
else
{
while(list($id, $name, $linktitle) = mysql_fetch_array($result))
{
echo "<a href=\"fchuploadedit.php?id=$id;\">
$linktitle
</a><BR />
<em>PDF Name: $name</em><br><br>";
}
}
echo "</td><td></td>
<p> </p>
<td align=\"center\" valign=\"top\"><p><strong>Current Wiring Diagrams:</strong></p>
<p>";
$query = "SELECT id, name, linktitle FROM upload WHERE section = 'wiring'";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result) == 0)
{
echo "Database is empty <br>";
}
else
{
while(list($id, $name, $linktitle) = mysql_fetch_array($result))
{
echo "<a href=\"fchuploadedit.php?id=$id;\">
$linktitle
</a><BR />
<em>PDF Name: $name</em><br><br>";
}
}
?>