Hi...something like this may help get you pointed in the right direction
<?
php require_once('/Connections/connect.php');
$colname_rsProject = "-1";
if (isset($_GET['ID'])) {
$colname_rsProjects = (get_magic_quotes_gpc()) ? $_GET['ID'] : addslashes($_GET['ID']);
}
mysql_select_db($database, $conn);
$query_rsProject = sprintf("SELECT * FROM dbtable WHERE ID = %s", $colname_rsProject);
$rsProject = mysql_query($query_rsProject, $conn) or die(mysql_error());
$row_rsProject = mysql_fetch_assoc($rsProject);
$totalRows_rsProject = mysql_num_rows($rsProject);
define ('MAX_FILE_SIZE', 2048000);
$AddData="No";
$MM_flag="MM_update";
if((isset($_POST["submit"])) && ($_POST["MM_update"] == "formname")) {
$AddData="Yes";
$startwarn="No";
/// image/file upload code begin
if (array_key_exists('submit', $_POST)) {
// define constant for upload folder
define('UPLOAD_DIR', 'you upload directory info here');
// replace any spaces in original filename with underscores
// and assign to a simpler variable
$file = str_replace(' ', '_', $_FILES['image']['name']);
// convert the maximum size to KB
$max = number_format(MAX_FILE_SIZE/1024, 1).'KB';
// create an array of permitted MIME types
$permitted = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/png');
// begin by assuming the file is unacceptable
$size_OK = false;
$type_OK = false;
// check that file is within the permitted size
if ($_FILES['image']['size'] > 0 && $_FILES['image']['size'] <= MAX_FILE_SIZE) {
$size_OK = true;
}
// check that file is of an permitted MIME type
foreach ($permitted as $type) {
if ($type == $_FILES['image']['type']) {
$type_OK = true;
break;
}
}
if ($size_OK && $type_OK) {
switch($_FILES['image']['error']) {
case 0:
// move the file to the upload folder and rename it
$success_OK = move_uploaded_file($_FILES['image']['tmp_name'], UPLOAD_DIR.$file);
if ($success_OK) {
$result1 = "$file has been uploaded successfully";
}
else {
$AddData = "No";
$result = "There was an error uploading $file. Please try again.";
}
break;
case 3:
$AddData = "No";
$result = "There was an error uploading $file. Please try again.";
default:
$AddData = "No";
$result = "System error uploading $file. Please contact the webmaster.";
}
}
elseif ($_FILES['image']['error'] == 4) {
$result1 = 'No file selected';
}
else {
$AddData = "No";
$result = "$file cannot be uploaded. Maximum size: $max. Acceptable file types: gif, jpg, png.";
}
}
if (isset($result)) {
$AddData = "No";
if ($startwarn=="No") { ?>
<div class="startwarning">Please complete the missing item(s) indicated. </div>
<?php $startwarn="Yes"; } ?>
<div class="warning"><li><?php echo $result; ?></li></div>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
$ID = $_POST['ID'];
mysql_select_db($database, $conn);
$query_rsUploads = ("SELECT * FROM db WHERE ID = '$ID' and FilePath = '$file'");
$rsUpload = mysql_query($query_rsUpload, $conn) or die(mysql_error());
$row_rsUpload = mysql_fetch_assoc($rsUpload);
$totalRows_rsUpload = mysql_num_rows($rsUpload);
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "formname") && $AddData!="No" && $totalRows_rsUpload == 0 && $file !="") {
$insert = sprintf("INSERT INTO dbtable (ID, FilePath) VALUES (%s, '$file')",
GetSQLValueString($_POST['ID'], "int"));
mysql_select_db($database, $conn);
$query_rsUploadFile = sprintf("SELECT * FROM dbtable WHERE ID = %s", $colname_rsProject);
$rsUploadFile = mysql_query($query_rsUploadFile, $conn) or die(mysql_error());
$row_rsUploadFile = mysql_fetch_assoc($rsUploadFile);
$totalRows_rsUploadFile = mysql_num_rows($rsUploadFile);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.warning {
background-color: #ffffee;
color: #660000;
width: 650px;
padding: 5px;
border-right-width: thin;
border-left-width: thin;
border-right-style: solid;
border-left-style: solid;
border-right-color: #FF0000;
border-left-color: #FF0000;
text-indent: 20px;
}
.warningend {
background-color: #ffffee;
color: #660000;
width: 650px;
padding: 5px;
border-right-width: thin;
border-left-width: thin;
border-right-style: solid;
border-left-style: solid;
border-right-color: #FF0000;
border-left-color: #FF0000;
border-bottom-width: thin;
border-bottom-style: solid;
border-bottom-color: #FF0000;
}
.startwarning {
background-color: #ffffee;
color: #660000;
width: 650px;
padding: 5px;
border-right-width: thin;
border-left-width: thin;
border-right-style: solid;
border-left-style: solid;
border-right-color: #FF0000;
border-left-color: #FF0000;
border-top-width: thin;
border-top-style: solid;
border-top-color: #FF0000;
}
.notify {
border: 1px solid #336699;
background-color: #ffffee;
color: #336699;
width: 650px;
padding: 5px;
}
-->
</style>
</head>
<body>
<form method="post" name="formname" action="<?php echo $editFormAction; ?>" enctype="multipart/form-data"/>
<?php
if (array_key_exists('submit', $_POST)) {
}
if($AddData=="no") {
?>
<input type="hidden" name="ID" value="<?php echo $row_rsProject['ID']; ?>" />
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MAX_FILE_SIZE; ?>" />
<input type="hidden" name="ID" value="<?php echo $row_rsProject['ID']; ?>">
<input type="file" name="image" id="image" size="70" />
<input type="submit" name="submit" value="Submit" />
<input type="hidden" name="MM_update" value="formname">
</form>
<?php
}
?>
</body>
</html>