h2oskierc Posted July 10, 2008 Share Posted July 10, 2008 I have the following code, which uploads an image to my server, and then stores that images name in a MySQL database: <?php session_start(); //define a constant for maximum upload size define ('MAX_FILE_SIZE', 512000); //store session variables to regular variables for ease of use $oldUserID = $_SESSION['custID']; $invoice = $_SESSION['invoice']; $numProofs = $_SESSION['numProofs']; $proofNum = $_SESSION['proofNum']; //create a session variable for remaining proofs after this one if session signs isn't set, set it equal to 1 if (!isset($_SESSION['signs'])) { $_SESSION['signs'] = 1; } $_SESSION['remainProofs'] = $numProofs - $_SESSION['signs']; $remainProof = $_SESSION['remainProofs']; //create a counter for sign number $signs = 1; //set the file name //get the date and time ini_set('date.timezone', 'America/Chicago'); $now = date('m-d-Y-His'); //set fileName variable for ease of coding $fileName = $now.'.jpg'; //$_SESSION['fileName'] = $fileName; $_SESSION['fileName.echo($signs)'] = $fileName; if (array_key_exists('create', $_POST)) { //define constant for upload folder define('UPLOAD_DIR', '/dellsigns/proofs/images/large/'); //replace any spaces in the original filename with underscores //at the same time, assign to a simpler variable $file = str_replace(' ', '_', $_FILES['proof']['name']); // convert 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 unnacceptable $sizeOK = false; $typeOK = false; //check that the file is within the permitted size if ($_FILES['proof']['size'] > 0 && $_FILES['proof']['size'] <= MAX_FILE_SIZE) { $sizeOK = true; } //check that the file is of a permitted type foreach ($permitted as $type) { if ($type == $_FILES['proof']['type']) { $typeOK = true; break; } } if ($sizeOK && $typeOK) { switch($_FILES['proof']['error']){ case 0: //move the file to the upload folder and rename it $success = move_uploaded_file($_FILES['proof']['tmp_name'],UPLOAD_DIR.$fileName); if ($success) { $result = "$file uploaded successfully"; } else { $result = "Error uploading $file. Please try again."; } break; case 3: $result = "Error uploading $file. Please try again."; default: $result = "System error uploading $file. Contact webmaster."; } } elseif ($_FILES['proof']['error'] == 4) { $result = 'No file selected.'; } else { $result = "$file cannot be uploaded. Maximum size: $max. Acceptable file types: gif, jpeg, png."; } } ?> <?php require_once('../Connections/proofs.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $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"] == "proofDetails")) { $insertSQL = sprintf("INSERT INTO signs (proofID, image, `size`, material, sided, colors, cost, notes) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['proofID'], "int"), GetSQLValueString($_POST['image'], "text"), GetSQLValueString($_POST['size'], "text"), GetSQLValueString($_POST['material'], "text"), GetSQLValueString($_POST['sided'], "text"), GetSQLValueString($_POST['colors'], "text"), GetSQLValueString($_POST['cost'], "text"), GetSQLValueString($_POST['notes'], "text")); mysql_select_db($database_proofs, $proofs); $Result1 = mysql_query($insertSQL, $proofs) or die(mysql_error()); //increase sign counter by one and assign to session variable $_SESSION['signs'] = ++$signs; //if no signs remain, redirect to proof preview page, else stay here if ($remainProof == 0) { $insertGoTo = "preview_proof.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo.'proofID='.$_POST['proofID'])); } } $var1_getProofID = "-1"; if (isset($oldUserID)) { $var1_getProofID = $oldUserID; } $var2_getProofID = "-1"; if (isset($invoice)) { $var2_getProofID = $invoice; } $var3_getProofID = "-1"; if (isset($numProofs)) { $var3_getProofID = $numProofs; } $var4_getProofID = "-1"; if (isset($proofNum)) { $var4_getProofID = $proofNum; } mysql_select_db($database_proofs, $proofs); $query_getProofID = sprintf("SELECT proofs.proofID FROM proofs WHERE proofs.userID = %s AND proofs.invoice = %s AND proofs.numProofs = %s AND proofs.proofNum = %s", GetSQLValueString($var1_getProofID, "int"),GetSQLValueString($var2_getProofID, "int"),GetSQLValueString($var3_getProofID, "int"),GetSQLValueString($var4_getProofID, "int")); $getProofID = mysql_query($query_getProofID, $proofs) or die(mysql_error()); $row_getProofID = mysql_fetch_assoc($getProofID); $totalRows_getProofID = mysql_num_rows($getProofID); ?> <!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=utf-8" /> <title>Dell Signs & Graphics Proofing System</title> <link href="../assets/styles/oneColFixCtrHdr.css" rel="stylesheet" type="text/css" /> <script src="../assets/spry/SpryMenuBar.js" type="text/javascript"></script> <link href="../assets/spry/SpryMenuBarHorizontal_nav.css" rel="stylesheet" type="text/css" /> </head> <body class="oneColFixCtrHdr"> <div id="container"> <div id="header"> <h1>Dell Signs & Graphics</h1> <img src="../assets/images/header.jpg" alt="Dell Signs & Graphics" width="780" height="179" /> <!-- end #header --> </div> <?php include('../assets/includes/nav.inc.php'); ?> <div id="mainContent"> <h1> Add Signs to Proof</h1> <p>Proof ID is <?php echo $row_getProofID['proofID']; ?> <form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="proofDetails" id="proofDetails"> <fieldset> <legend>Sign <?php echo $signs; ?>, <?php echo($remainProof); ?> sign<?php if ($remainProof-1 >= 2) { echo 's'; } ?> remain<?php if ($remainProof-1 == 0) { echo 's'; } ?>.</legend> <label for="proof"><br /> <input name="proofID" type="hidden" id="proofID" value="<?php echo $row_getProofID['proofID']; ?>" /> Proof Image:</label> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MAX_FILE_SIZE; ?> " /> <input type="file" name="proof" id="proof" /> <input name="image" type="hidden" id="image" value="<?php echo $_SESSION['fileName.echo($signs)']; ?>" /> <p> <label for="size">Sign Size:</label> <input type="text" name="size" id="size" /> </p> <p> <label> <input type="radio" name="sided" value="s" id="sided_0" /> Single Sided</label> <br /> <label> <input type="radio" name="sided" value="d" id="sided_1" /> Double Sided</label> </p> <p> <label for="colors">Sign Colors:</label> <input type="text" name="colors" id="colors" /> </p> <p> <label for="material">Sign Materials:</label> <input type="text" name="material" id="material" /> </p> <p> <label for="cost">Sign Cost:</label> <input type="text" name="cost" id="cost" /> </p> <p> <label for="notes">Sign Notes:<br /> <br /> </label> <textarea name="notes" id="notes" cols="45" rows="5"></textarea> </p> </fieldset> <p> <input type="submit" name="create" id="create" value="Create Sign" /> </p> <input type="hidden" name="MM_insert" value="proofDetails" /> </form> </div> <?php include('../assets/includes/footer.inc.php'); ?> <!-- end #container --></div> </body> </html> <?php mysql_free_result($getProofID); //unset the fileName session variable unset($_SESSION['fileName']); ?> The file is renamed to a timestamp, and then that same timestamp is supposed to be written to a field called image in the DB. The problem is that the image is given one timestamp (upload completes successfuly), and the DB is given a different time-stamp. Can anybody tell where the problem is coming in? Sorry for posting so much code, I just thought you may need to see the entire page in order to see where everything comes into play. Thanks in advance for any help! Link to comment https://forums.phpfreaks.com/topic/114080-solved-timestamp-issues/ Share on other sites More sharing options...
discomatt Posted July 10, 2008 Share Posted July 10, 2008 Wow, that's a lot of vague code to go through, but I think your problem lies here $insertSQL = sprintf("INSERT INTO signs (proofID, image, `size`, material, sided, colors, cost, notes) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['proofID'], "int"), GetSQLValueString($_POST['image'], "text"), GetSQLValueString($_POST['size'], "text"), GetSQLValueString($_POST['material'], "text"), GetSQLValueString($_POST['sided'], "text"), GetSQLValueString($_POST['colors'], "text"), GetSQLValueString($_POST['cost'], "text"), GetSQLValueString($_POST['notes'], "text")); Why are you inserting $_POST['image'] and not the $fileName var you created before $now = date('m-d-Y-His'); //set fileName variable for ease of coding $fileName = $now.'.jpg'; Link to comment https://forums.phpfreaks.com/topic/114080-solved-timestamp-issues/#findComment-586362 Share on other sites More sharing options...
h2oskierc Posted July 10, 2008 Author Share Posted July 10, 2008 Awesome, I'll check that out real quick! Link to comment https://forums.phpfreaks.com/topic/114080-solved-timestamp-issues/#findComment-586371 Share on other sites More sharing options...
h2oskierc Posted July 10, 2008 Author Share Posted July 10, 2008 That did it! Thanks a million. Ive been pouring over this code for hours, and missed something so obvious! Link to comment https://forums.phpfreaks.com/topic/114080-solved-timestamp-issues/#findComment-586375 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.