I have a edit page that can uploads an image and updates mySQL with the file name. They problem I have is if the file field is left blank it inserts a null value to the name field. I need it to keep the original file name if the file field is left blank.
thanks for any help.
<?php require_once('../../Connections/conn_chapel.php'); ?>
<?php require_once('../../ScriptLibrary/incPureUpload.php'); ?>
<?php require_once('../../ScriptLibrary/incResize.php'); ?>
<?php
// Pure PHP Upload 2.1.2
if (isset($HTTP_GET_VARS['GP_upload'])) {
$ppu = new pureFileUpload();
$ppu->path = "../image_upload";
$ppu->extensions = "GIF,JPG,JPEG,BMP,PNG";
$ppu->formName = "form1";
$ppu->storeType = "file";
$ppu->sizeLimit = "";
$ppu->nameConflict = "uniq";
$ppu->requireUpload = "false";
$ppu->minWidth = "";
$ppu->minHeight = "";
$ppu->maxWidth = "";
$ppu->maxHeight = "";
$ppu->saveWidth = "";
$ppu->saveHeight = "";
$ppu->timeout = "600";
$ppu->progressBar = "fileCopyProgress.htm";
$ppu->progressWidth = "300";
$ppu->progressHeight = "100";
$ppu->checkVersion("2.1.2");
$ppu->doUpload();
}
$GP_uploadAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
if (!eregi("GP_upload=true", $HTTP_SERVER_VARS['QUERY_STRING'])) {
$GP_uploadAction .= "?".$HTTP_SERVER_VARS['QUERY_STRING']."&GP_upload=true";
} else {
$GP_uploadAction .= "?".$HTTP_SERVER_VARS['QUERY_STRING'];
}
} else {
$GP_uploadAction .= "?"."GP_upload=true";
}
// Smart Image Processor 1.0.3
if (isset($HTTP_GET_VARS['GP_upload'])) {
$sip = new resizeUploadedFiles($ppu);
$sip->component = "GD2";
$sip->resizeImages = "true";
$sip->aspectImages = "true";
$sip->maxWidth = "175";
$sip->maxHeight = "";
$sip->quality = "80";
$sip->makeThumb = "false";
$sip->pathThumb = "";
$sip->aspectThumb = "true";
$sip->naming = "suffix";
$sip->suffix = "_small";
$sip->maxWidthThumb = "";
$sip->maxHeightThumb = "";
$sip->qualityThumb = "70";
$sip->checkVersion("1.0.3");
$sip->doResize();
}
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 != "") ? "'" . date("Y-m-d",strtotime($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']);
}
if (isset($editFormAction)) {
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
if (!eregi("GP_upload=true", $HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "&GP_upload=true";
}
} else {
$editFormAction .= "?GP_upload=true";
}
}
if ((isset($HTTP_POST_VARS["MM_update"])) && ($HTTP_POST_VARS["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE images SET image=%s WHERE ID=%s",
GetSQLValueString($HTTP_POST_VARS['image1'], "text"),
GetSQLValueString($HTTP_POST_VARS['ID'], "int"));
mysql_select_db($database_conn_chapel, $conn_chapel);
$Result1 = mysql_query($updateSQL, $conn_chapel) or die(mysql_error());
$updateGoTo = "image-test.php";
if (isset($SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
mysql_select_db($database_conn_chapel, $conn_chapel);
$query_rs_general = "SELECT * FROM gereneral";
$rs_general = mysql_query($query_rs_general, $conn_chapel) or die(mysql_error());
$row_rs_general = mysql_fetch_assoc($rs_general);
$totalRows_rs_general = mysql_num_rows($rs_general);
$colname_rs_image = "1";
if (isset($GET['locate'])) {
$colname_rs_image = (get_magic_quotes_gpc()) ? $GET['locate'] : addslashes($_GET['locate']);
}
mysql_select_db($database_conn_chapel, $conn_chapel);
$query_rs_image = sprintf("SELECT * FROM images WHERE locate = '%s'", $colname_rs_image);
$rs_image = mysql_query($query_rs_image, $conn_chapel) or die(mysql_error());
$row_rs_image = mysql_fetch_assoc($rs_image);
$totalRows_rs_image = mysql_num_rows($rs_image);
?>
As you see I use Dreamweave and I dont know much PHP as it writes most of it.
Thanks again for any help.