I have been banging my head against a wall for two days trying to insert a record into the mySql DB and (at the same time) upload an image file to the server. I downloaded Sephiroth PHP Upload from Adobe, and it works by it self to upload a photo to my file "uploads". The Record Form Insertion Wizard from Dream Weaver CS4 works on its own too. When I combined the two, only the DB is updated with the correct info. The upload file is empty. How do I tie the two (PHP Upload & Insertion Wizard) togather?
<?php
if (phpversion() > "4.0.6") {
$HTTP_POST_FILES = &$_FILES;
}
define("MAX_SIZE",300000);
define("DESTINATION_FOLDER", "../uploads");
define("no_error", "../ok.html");
define("yes_error", "../error.html");
$_accepted_extensions_ = "jpg,gif,png";
if(strlen($_accepted_extensions_) > 0){
$_accepted_extensions_ = @explode(",",$_accepted_extensions_);
} else {
$_accepted_extensions_ = array();
}
$_file_ = $HTTP_POST_FILES['fullSize'];
if(is_uploaded_file($_file_['tmp_name']) && $HTTP_POST_FILES['fullSize']['error'] == 0){
$errStr = "";
$_name_ = $_file_['name'];
$_type_ = $_file_['type'];
$_tmp_name_ = $_file_['tmp_name'];
$_size_ = $_file_['size'];
if($_size_ > MAX_SIZE && MAX_SIZE > 0){
$errStr = "File troppo pesante";
}
$_ext_ = explode(".", $_name_);
$_ext_ = strtolower($_ext_[count($_ext_)-1]);
if(!in_array($_ext_, $_accepted_extensions_) && count($_accepted_extensions_) > 0){
$errStr = "Estensione non valida";
}
if(!is_dir(DESTINATION_FOLDER) && is_writeable(DESTINATION_FOLDER)){
$errStr = "Cartella di destinazione non valida";
}
if(empty($errStr)){
if(@copy($_tmp_name_,DESTINATION_FOLDER . "/" . $_name_)){
header("Location: " . no_error);
} else {
header("Location: " . yes_error);
}
} else {
header("Location: " . yes_error);
}
}
?>
//end of Sephiroth PHP Upload
//Beginning of Insertion Wizard
<?php require_once('../Connections/connAlly.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
$insertSQL = sprintf("INSERT INTO portfolio (imageTitle, projectName, fullSize, kitchen, bath) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($_POST['imageTitle'], "text"),
GetSQLValueString($_POST['projectName'], "text"),
GetSQLValueString($_POST['fullSize'], "text"),
GetSQLValueString(isset($_POST['kitchen']) ? "true" : "", "defined","1","0"),
GetSQLValueString(isset($_POST['bath']) ? "true" : "", "defined","1","0"));
mysql_select_db($database_connAlly, $connAlly);
$Result1 = mysql_query($insertSQL, $connAlly) or die(mysql_error());
$insertGoTo = "../ok.html";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
HTML Code:
<html xmlns="http://www.w3.org/1999/xhtml">
<form action="<?php echo $editFormAction; ?>" method="post" name="form2" id="form2">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">ImageTitle:</td>
<td><input type="text" name="imageTitle" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">ProjectName:</td>
<td><input type="text" name="projectName" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Photo:</td>
<td><input type="file" name="fullSize" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Kitchen:</td>
<td><input type="checkbox" name="kitchen" value="" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Bath:</td>
<td><input type="checkbox" name="bath" value="" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input type="submit" value="Insert record" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form2" />
</form>
</html>