[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Upload working, update not in PHP MySQL database

Posted on 2009-04-28
25
Medium Priority
?
798 Views
Last Modified: 2013-12-12
I am working on a project for apartment managers to upload necessary files for tenants to read when they login on their end. This particular page, updates an already existing record with a new file.
The upload portion is working fine, I can see the uploaded file in my file manager.
The MySQL database field is not updating, file_url is a blank field in phpMyAdmin.

I have an error message implemented if there is a problem, the error message is:

"There was an error uploading the file, please try again! Here is some more debugging info:
Array ( [upfile] => Array ( [name] => blue.jpg [type] => image/jpeg [tmp_name] => /tmp/phpDs6L6d [error] => 0 [size] => 17450 ) ) "

I can't figure out what is happening with the tmp_name to fix it. I'm using the Dreamweaver CS3 Extension PHP Pure Upload.

I've posted my code below.
<?php require_once('../../Connections/boulders.php'); ?>
<?php require_once('../../ScriptLibrary/incPureUpload.php'); ?>
<?php include("../admin.php"); include("../chkuser.php") ?>
<?php
// Pure PHP Upload 2.1.7
$ppu = new pureFileUpload();
$ppu->path = "/home/content/s/h/o/shockoe/html/communities/boulders/";
$ppu->extensions = "";
$ppu->formName = "replace_doc";
$ppu->storeType = "file";
$ppu->sizeLimit = "";
$ppu->nameConflict = "over";
$ppu->requireUpload = "true";
$ppu->minWidth = "";
$ppu->minHeight = "";
$ppu->maxWidth = "";
$ppu->maxHeight = "";
$ppu->saveWidth = "";
$ppu->saveHeight = "";
$ppu->timeout = "600";
$ppu->progressBar = "../blueFlashProgress.htm";
$ppu->progressWidth = "300";
$ppu->progressHeight = "100";
$ppu->redirectURL = "";
$ppu->checkVersion("2.1.7");
$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";
}
 
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 (!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;
}
}
 
 
$colname_condo_doc = "-1";
if (isset($_GET['id'])) {
  $colname_condo_doc = $_GET['id'];
}
 
mysql_select_db($database_boulders, $boulders);
$query_condo_doc = sprintf("SELECT * FROM condo_docs2 WHERE id = %s", GetSQLValueString($colname_condo_doc, "int"));
$condo_doc = mysql_query($query_condo_doc, $boulders) or die(mysql_error());
$row_condo_doc = mysql_fetch_assoc($condo_doc);
$totalRows_condo_doc = mysql_num_rows($condo_doc);
?><!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><?= $SITE_TITLE ?></title>
<link href="../admin.css" rel="stylesheet" type="text/css" />
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
</head>
 
 
<body>
<? include("../nav.php") ?>
<? include("nav2.php") ?>
<div id="wrapper_sub">
<br />
 
 
 <p>Use this form to replace an already exisiting document with an updated version.</p>
<p>Uploading will replace the document <strong><?php echo $row_condo_doc['file_url']; ?></strong>. It is identified with the link text of <strong><?php echo $row_condo_doc['name']; ?></strong> in the category of <?php if ($row_condo_docs['category'] == 0) {
	echo '<strong>Rules, Regulations</strong>';
	}
	elseif ($row_condo_docs['category'] == 1) {
	echo '<strong>Other Docs</strong>';
	}  ?>.</p>
<fieldset>
<legend>Replace Condo Doc</legend>
<div>
<h2>
  <?php
//if ((isset($_POST["MM_update"])) && ($_POST["MM_update"])) {
if (isset($_POST['Submit'])){
 
$uploadLocation = "/home/content/s/h/o/shockoe/html/communities/boulders/";
 
 
	//converting upfile array name variable to a single variable
	$filenm=$_FILES['upfile']['name'];
	
	//converts spaces in filenames to underscore - from http://www.phpit.net/code/filename-safe/
	 $filename=preg_replace ('/ {1,}/', '_', trim ($filenm));
	
 
	//the sql update statement converted to a variable
   $updateSQL = sprintf("UPDATE condo_docs2 SET `date`=%s, `file_url`=%s WHERE id=%s",
                       GetSQLValueString($_POST['date'], "date"),
                       GetSQLValueString($_POST['filenm'], "text"),
					   GetSQLValueString($_POST['id'], "int"));
 
  mysql_select_db($database_boulders, $boulders);
  $Result1 = mysql_query($updateSQL, $boulders) or die(mysql_error());
?>
    </h2>
<div id="caption">RESULT</div>
      <div id="icon2">&nbsp;</div>
      <div id="result">
        <table width="100%">
<?php
 
//vreating target path variable
 
$target_path = $uploadLocation . basename( $filename);
 
//moving file from tmp to  upload directory
if(move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path)) {
    
	//response after execution
	echo "<p>The file: ".  basename( $_FILES['upfile']['name']).
    " has been uploaded!</p> ";
	
	echo "<p>Thank you for your submission.</p>";
	echo "<p>Click here to <a href=\"condos_aa.php\">return to the form Condo Docs Upload Form</a>.</p>";
 
	echo "<p>Close the window to Log out.</p>";
} else{
    echo "There was an error uploading the file, please try again!";
	echo 'Here is some more debugging info:';
print_r($_FILES);
}
 
?>
        </table>
     </div>
  <?php  } else {
 
 
?>
<form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="replace_doc" id="replace_doc" onsubmit="checkFileUpload(this,'',true,'','','','','','','');showProgressWindow('blueFlashProgress.htm',300,100);return document.MM_returnValue">
 
  <p>
    <input name="date" type="hidden" value="<?php $today = date("Ymd"); echo $today; ?>" />
    <input name="id" type="hidden" value="<?php echo $_GET['id']; ?>" />
    <input name="upfile" type="file" id="upfile" onchange="checkOneFileUpload(this,'',true,'','','','','','','')" />
    <br />
    <br />
    <input type="submit" name="Submit" id="Submit" value="Submit" />
  </p>
  <input type="hidden" name="MM_update" value="replace_doc" />
</form>
</fieldset>
<?php } ?>
</div>
 
</body>
</html>
<?php
mysql_free_result($condo_doc);
?>

Open in new window

0
Comment
Question by:kentcommunications
  • 13
  • 8
  • 2
  • +1
25 Comments
 
LVL 4

Expert Comment

by:joep1978
ID: 24253877
When you say you can see the file in Filemanager, is this inside /home/content/s/h/o/shockoe/html/communities/boulders/ ?

The error that is being generated seems like nothing to with MySQL - it's generated trying to copy the temporary file (/tmp/phpDs6L6d) to the upload folder (which looks to be /home/content/s/h/o/shockoe/html/communities/boulders/)

My first instinct would be change to the permissions of the target folder on the server by running:-

chmod 0777 /home/content/s/h/o/shockoe/html/communities/boulders/



0
 

Author Comment

by:kentcommunications
ID: 24254179
When I said I see the file in the file manager, I was referring to my host, GoDaddy's online file manager. I can also browse to the file looking at the "remote" side of my FTP Client.
I had originally thought it was an issue with folder permissions to. I set it manually, and called my host to confirm it. The folders are set for 0777.
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 24255186
Try changing the globals:

currently: $HTTP_SERVER_VARS

change to: $_SERVER

and see if that makes a difference.
0
Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

 
LVL 20

Expert Comment

by:NerdsOfTech
ID: 24255539
The error is in the SQL statement. Will research.
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 24255553
NoT,

If the error is in the SQL, it has to be this line:

GetSQLValueString($_POST['filenm'], "text"),


Where the $_POST['filenm'] is not being set properly...
0
 
LVL 4

Expert Comment

by:joep1978
ID: 24255725
I think there is an error in the SQL - there are no '' around the strings in sprintf.  I've modified that here, let me know if it works.  However I don't know yet why you get the message:-

"There was an error uploading the file, please try again!"

That error message only occurs if the call to move_uploaded_file() fails and the paths seem sane.  Can you output $targetPath in the extra debugging info?

<?php require_once('../../Connections/boulders.php'); ?>
<?php require_once('../../ScriptLibrary/incPureUpload.php'); ?>
<?php include("../admin.php"); include("../chkuser.php") ?>
<?php
// Pure PHP Upload 2.1.7
$ppu = new pureFileUpload();
$ppu->path = "/home/content/s/h/o/shockoe/html/communities/boulders/";
$ppu->extensions = "";
$ppu->formName = "replace_doc";
$ppu->storeType = "file";
$ppu->sizeLimit = "";
$ppu->nameConflict = "over";
$ppu->requireUpload = "true";
$ppu->minWidth = "";
$ppu->minHeight = "";
$ppu->maxWidth = "";
$ppu->maxHeight = "";
$ppu->saveWidth = "";
$ppu->saveHeight = "";
$ppu->timeout = "600";
$ppu->progressBar = "../blueFlashProgress.htm";
$ppu->progressWidth = "300";
$ppu->progressHeight = "100";
$ppu->redirectURL = "";
$ppu->checkVersion("2.1.7");
$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";
}
 
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 (!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;
}
}
 
 
$colname_condo_doc = "-1";
if (isset($_GET['id'])) {
  $colname_condo_doc = $_GET['id'];
}
 
mysql_select_db($database_boulders, $boulders);
$query_condo_doc = sprintf("SELECT * FROM condo_docs2 WHERE id = '%s'", GetSQLValueString($colname_condo_doc, "int"));
$condo_doc = mysql_query($query_condo_doc, $boulders) or die(mysql_error());
$row_condo_doc = mysql_fetch_assoc($condo_doc);
$totalRows_condo_doc = mysql_num_rows($condo_doc);
?><!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><?= $SITE_TITLE ?></title>
<link href="../admin.css" rel="stylesheet" type="text/css" />
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
</head>
 
 
<body>
<? include("../nav.php") ?>
<? include("nav2.php") ?>
<div id="wrapper_sub">
<br />
 
 
 <p>Use this form to replace an already exisiting document with an updated version.</p>
<p>Uploading will replace the document <strong><?php echo $row_condo_doc['file_url']; ?></strong>. It is identified with the link text of <strong><?php echo $row_condo_doc['name']; ?></strong> in the category of <?php if ($row_condo_docs['category'] == 0) {
        echo '<strong>Rules, Regulations</strong>';
        }
        elseif ($row_condo_docs['category'] == 1) {
        echo '<strong>Other Docs</strong>';
        }  ?>.</p>
<fieldset>
<legend>Replace Condo Doc</legend>
<div>
<h2>
  <?php
//if ((isset($_POST["MM_update"])) && ($_POST["MM_update"])) {
if (isset($_POST['Submit'])){
 
$uploadLocation = "/home/content/s/h/o/shockoe/html/communities/boulders/";
 
 
        //converting upfile array name variable to a single variable
        $filenm=$_FILES['upfile']['name'];
        
        //converts spaces in filenames to underscore - from http://www.phpit.net/code/filename-safe/
         $filename=preg_replace ('/ {1,}/', '_', trim ($filenm));
        
 
        //the sql update statement converted to a variable
   $updateSQL = sprintf("UPDATE condo_docs2 SET `date`='%s', `file_url`='%s' WHERE id='%s'",
                       GetSQLValueString($_POST['date'], "date"),
                       GetSQLValueString($_POST['filenm'], "text"),
                                           GetSQLValueString($_POST['id'], "int"));
 
  mysql_select_db($database_boulders, $boulders);
  $Result1 = mysql_query($updateSQL, $boulders) or die(mysql_error());
?>
    </h2>
<div id="caption">RESULT</div>
      <div id="icon2"> </div>
      <div id="result">
        <table width="100%">
<?php
 
//vreating target path variable
 
$target_path = $uploadLocation . basename( $filename);
 
//moving file from tmp to  upload directory
if(move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path)) {
    
        //response after execution
        echo "<p>The file: ".  basename( $_FILES['upfile']['name']).
    " has been uploaded!</p> ";
        
        echo "<p>Thank you for your submission.</p>";
        echo "<p>Click here to <a href=\"condos_aa.php\">return to the form Condo Docs Upload Form</a>.</p>";
 
        echo "<p>Close the window to Log out.</p>";
} else{
    echo "There was an error uploading the file, please try again!";
        echo 'Here is some more debugging info:';
print_r($_FILES);
}
 
?>
        </table>
     </div>
  <?php  } else {
 
 
?>
<form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="replace_doc" id="replace_doc" onsubmit="checkFileUpload(this,'',true,'','','','','','','');showProgressWindow('blueFlashProgress.htm',300,100);return document.MM_returnValue">
 
  <p>
    <input name="date" type="hidden" value="<?php $today = date("Ymd"); echo $today; ?>" />
    <input name="id" type="hidden" value="<?php echo $_GET['id']; ?>" />
    <input name="upfile" type="file" id="upfile" onchange="checkOneFileUpload(this,'',true,'','','','','','','')" />
    <br />
    <br />
    <input type="submit" name="Submit" id="Submit" value="Submit" />
  </p>
  <input type="hidden" name="MM_update" value="replace_doc" />
</form>
</fieldset>
<?php } ?>
</div>
 
</body>
</html>

Open in new window

0
 
LVL 20

Expert Comment

by:NerdsOfTech
ID: 24256367
Use $filename in your sprintf instead that is why you are getting a null field.
0
 
LVL 20

Accepted Solution

by:
NerdsOfTech earned 2000 total points
ID: 24258085
My phone didn't allow me to copy and paste :(

Back in my office. So here it is!

:)
<?php require_once('../../Connections/boulders.php'); ?>
<?php require_once('../../ScriptLibrary/incPureUpload.php'); ?>
<?php include("../admin.php"); include("../chkuser.php") ?>
<?php
// Pure PHP Upload 2.1.7
$ppu = new pureFileUpload();
$ppu->path = "/home/content/s/h/o/shockoe/html/communities/boulders/";
$ppu->extensions = "";
$ppu->formName = "replace_doc";
$ppu->storeType = "file";
$ppu->sizeLimit = "";
$ppu->nameConflict = "over";
$ppu->requireUpload = "true";
$ppu->minWidth = "";
$ppu->minHeight = "";
$ppu->maxWidth = "";
$ppu->maxHeight = "";
$ppu->saveWidth = "";
$ppu->saveHeight = "";
$ppu->timeout = "600";
$ppu->progressBar = "../blueFlashProgress.htm";
$ppu->progressWidth = "300";
$ppu->progressHeight = "100";
$ppu->redirectURL = "";
$ppu->checkVersion("2.1.7");
$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";
}
 
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 (!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;
}
}
 
 
$colname_condo_doc = "-1";
if (isset($_GET['id'])) {
  $colname_condo_doc = $_GET['id'];
}
 
mysql_select_db($database_boulders, $boulders);
$query_condo_doc = sprintf("SELECT * FROM condo_docs2 WHERE id = %s", GetSQLValueString($colname_condo_doc, "int"));
$condo_doc = mysql_query($query_condo_doc, $boulders) or die(mysql_error());
$row_condo_doc = mysql_fetch_assoc($condo_doc);
$totalRows_condo_doc = mysql_num_rows($condo_doc);
?><!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><?= $SITE_TITLE ?></title>
<link href="../admin.css" rel="stylesheet" type="text/css" />
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
</head>
 
 
<body>
<? include("../nav.php") ?>
<? include("nav2.php") ?>
<div id="wrapper_sub">
<br />
 
 
 <p>Use this form to replace an already exisiting document with an updated version.</p>
<p>Uploading will replace the document <strong><?php echo $row_condo_doc['file_url']; ?></strong>. It is identified with the link text of <strong><?php echo $row_condo_doc['name']; ?></strong> in the category of <?php if ($row_condo_docs['category'] == 0) {
	echo '<strong>Rules, Regulations</strong>';
	}
	elseif ($row_condo_docs['category'] == 1) {
	echo '<strong>Other Docs</strong>';
	}  ?>.</p>
<fieldset>
<legend>Replace Condo Doc</legend>
<div>
<h2>
  <?php
//if ((isset($_POST["MM_update"])) && ($_POST["MM_update"])) {
if (isset($_POST['Submit'])){
 
$uploadLocation = "/home/content/s/h/o/shockoe/html/communities/boulders/";
 
 
	//converting upfile array name variable to a single variable
	$filenm=$_FILES['upfile']['name'];
	
	//converts spaces in filenames to underscore - from http://www.phpit.net/code/filename-safe/
	 $filename=preg_replace ('/ {1,}/', '_', trim ($filenm));
	
 
	//the sql update statement converted to a variable
   $updateSQL = sprintf("UPDATE condo_docs2 SET `date`=%s, `file_url`=%s WHERE id=%s",
                       GetSQLValueString($_POST['date'], "date"),
                       GetSQLValueString($filename, "text"),
					   GetSQLValueString($_POST['id'], "int"));
 
  mysql_select_db($database_boulders, $boulders);
  $Result1 = mysql_query($updateSQL, $boulders) or die(mysql_error());
?>
    </h2>
<div id="caption">RESULT</div>
      <div id="icon2">&nbsp;</div>
      <div id="result">
        <table width="100%">
<?php
 
//vreating target path variable
 
$target_path = $uploadLocation . basename( $filename);
 
//moving file from tmp to  upload directory
if(move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path)) {
    
	//response after execution
	echo "<p>The file: ".  basename( $_FILES['upfile']['name']).
    " has been uploaded!</p> ";
	
	echo "<p>Thank you for your submission.</p>";
	echo "<p>Click here to <a href=\"condos_aa.php\">return to the form Condo Docs Upload Form</a>.</p>";
 
	echo "<p>Close the window to Log out.</p>";
} else{
    echo "There was an error uploading the file, please try again!";
	echo 'Here is some more debugging info:';
print_r($_FILES);
}
 
?>
        </table>
     </div>
  <?php  } else {
 
 
?>
<form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="replace_doc" id="replace_doc" onsubmit="checkFileUpload(this,'',true,'','','','','','','');showProgressWindow('blueFlashProgress.htm',300,100);return document.MM_returnValue">
 
  <p>
    <input name="date" type="hidden" value="<?php $today = date("Ymd"); echo $today; ?>" />
    <input name="id" type="hidden" value="<?php echo $_GET['id']; ?>" />
    <input name="upfile" type="file" id="upfile" onchange="checkOneFileUpload(this,'',true,'','','','','','','')" />
    <br />
    <br />
    <input type="submit" name="Submit" id="Submit" value="Submit" />
  </p>
  <input type="hidden" name="MM_update" value="replace_doc" />
</form>
</fieldset>
<?php } ?>
</div>
 
</body>
</html>
<?php
mysql_free_result($condo_doc);
?>

Open in new window

0
 
LVL 20

Expert Comment

by:NerdsOfTech
ID: 24258122
Also, you don't need the quote marks for GetSQLValueString() if the string is in variable reference form.

Changed Line:

$updateSQL = sprintf("UPDATE condo_docs2 SET `date`=%s, `file_url`=%s WHERE id=%s",
                       GetSQLValueString($_POST['date'], "date"),
                       GetSQLValueString($filename, "text"),
                                 GetSQLValueString($_POST['id'], "int"));
0
 

Author Comment

by:kentcommunications
ID: 24261075
NerdsOfTech,

Thanks for the code, it does work!  well...mostly. The file is being updated in the database and it is being uploaded correctly. The only problem is that the error still shows up, even though everything was successful as far as I can tell. The people who use this have a habit of not refreshing their browser and assuming it didn't post, I don't want to give them another reason to double post!

Error is the same as the original I posted. I know it is happening in the if...else statement somewhere
0
 
LVL 20

Expert Comment

by:NerdsOfTech
ID: 24262351
Looks like you are working with a windows server which needs the drive path too.

Added:
$currentdir=getcwd(); // keep for windows servers only
Changed:
$target_path = $currentdir . $uploadLocation . basename($filename);
<?php require_once('../../Connections/boulders.php'); ?>
<?php require_once('../../ScriptLibrary/incPureUpload.php'); ?>
<?php include("../admin.php"); include("../chkuser.php") ?>
<?php
// Pure PHP Upload 2.1.7
$ppu = new pureFileUpload();
$ppu->path = "/home/content/s/h/o/shockoe/html/communities/boulders/";
$ppu->extensions = "";
$ppu->formName = "replace_doc";
$ppu->storeType = "file";
$ppu->sizeLimit = "";
$ppu->nameConflict = "over";
$ppu->requireUpload = "true";
$ppu->minWidth = "";
$ppu->minHeight = "";
$ppu->maxWidth = "";
$ppu->maxHeight = "";
$ppu->saveWidth = "";
$ppu->saveHeight = "";
$ppu->timeout = "600";
$ppu->progressBar = "../blueFlashProgress.htm";
$ppu->progressWidth = "300";
$ppu->progressHeight = "100";
$ppu->redirectURL = "";
$ppu->checkVersion("2.1.7");
$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";
}
 
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 (!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;
}
}
 
 
$colname_condo_doc = "-1";
if (isset($_GET['id'])) {
  $colname_condo_doc = $_GET['id'];
}
 
mysql_select_db($database_boulders, $boulders);
$query_condo_doc = sprintf("SELECT * FROM condo_docs2 WHERE id = %s", GetSQLValueString($colname_condo_doc, "int"));
$condo_doc = mysql_query($query_condo_doc, $boulders) or die(mysql_error());
$row_condo_doc = mysql_fetch_assoc($condo_doc);
$totalRows_condo_doc = mysql_num_rows($condo_doc);
?><!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><?= $SITE_TITLE ?></title>
<link href="../admin.css" rel="stylesheet" type="text/css" />
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
</head>
 
 
<body>
<? include("../nav.php") ?>
<? include("nav2.php") ?>
<div id="wrapper_sub">
<br />
 
 
 <p>Use this form to replace an already exisiting document with an updated version.</p>
<p>Uploading will replace the document <strong><?php echo $row_condo_doc['file_url']; ?></strong>. It is identified with the link text of <strong><?php echo $row_condo_doc['name']; ?></strong> in the category of <?php if ($row_condo_docs['category'] == 0) {
	echo '<strong>Rules, Regulations</strong>';
	}
	elseif ($row_condo_docs['category'] == 1) {
	echo '<strong>Other Docs</strong>';
	}  ?>.</p>
<fieldset>
<legend>Replace Condo Doc</legend>
<div>
<h2>
  <?php
//if ((isset($_POST["MM_update"])) && ($_POST["MM_update"])) {
if (isset($_POST['Submit'])){
 
 $uploadLocation = "/home/content/s/h/o/shockoe/html/communities/boulders/";
 
 //converting upfile array name variable to a single variable
 $filenm=$_FILES['upfile']['name'];
	
 //converts spaces in filenames to underscore - from http://www.phpit.net/code/filename-safe/
 $filename=preg_replace ('/ {1,}/', '_', trim ($filenm));
	
 //the sql update statement converted to a variable
 $updateSQL = sprintf("UPDATE condo_docs2 SET `date`=%s, `file_url`=%s WHERE id=%s",
                       GetSQLValueString($_POST['date'], "date"),
                       GetSQLValueString($filename, "text"),
					   GetSQLValueString($_POST['id'], "int"));
 
  mysql_select_db($database_boulders, $boulders);
  $Result1 = mysql_query($updateSQL, $boulders) or die(mysql_error());
?>
    </h2>
<div id="caption">RESULT</div>
      <div id="icon2">&nbsp;</div>
      <div id="result">
        <table width="100%">
<?php
 
//vreating target path variable
 
 
$currentdir=getcwd(); // keep for windows servers only
$target_path = $currentdir . $uploadLocation . basename($filename);
 
//moving file from tmp to  upload directory
if(move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path)) {
    
	//response after execution
	echo "<p>The file: ".  basename( $_FILES['upfile']['name']).
    " has been uploaded!</p> ";
	
	echo "<p>Thank you for your submission.</p>";
	echo "<p>Click here to <a href=\"condos_aa.php\">return to the form Condo Docs Upload Form</a>.</p>";
 
	echo "<p>Close the window to Log out.</p>";
} else{
    echo "There was an error uploading the file, please try again!";
	echo 'Here is some more debugging info:';
print_r($_FILES);
}
 
?>
        </table>
     </div>
  <?php  } else {
 
 
?>
<form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="replace_doc" id="replace_doc" onsubmit="checkFileUpload(this,'',true,'','','','','','','');showProgressWindow('blueFlashProgress.htm',300,100);return document.MM_returnValue">
 
  <p>
    <input name="date" type="hidden" value="<?php $today = date("Ymd"); echo $today; ?>" />
    <input name="id" type="hidden" value="<?php echo $_GET['id']; ?>" />
    <input name="upfile" type="file" id="upfile" onchange="checkOneFileUpload(this,'',true,'','','','','','','')" />
    <br />
    <br />
    <input type="submit" name="Submit" id="Submit" value="Submit" />
  </p>
  <input type="hidden" name="MM_update" value="replace_doc" />
</form>
</fieldset>
<?php } ?>
</div>
 
</body>
</html>
<?php
mysql_free_result($condo_doc);
?>

Open in new window

0
 

Author Comment

by:kentcommunications
ID: 24263502
I'm actually working on a Linux server, double checked with the host. I also tried the code, to no avail.
Any problems that anyone else can see?
0
 
LVL 20

Expert Comment

by:NerdsOfTech
ID: 24264135
Okay is the upload path CHMOD'd for write permissions?

I put this above the last if statement:

echo $target_path;

Check that directory's permissions

Thanks.

=NerdsOfTech

<?php require_once('../../Connections/boulders.php'); ?>
<?php require_once('../../ScriptLibrary/incPureUpload.php'); ?>
<?php include("../admin.php"); include("../chkuser.php") ?>
<?php
// Pure PHP Upload 2.1.7
$ppu = new pureFileUpload();
$ppu->path = "/home/content/s/h/o/shockoe/html/communities/boulders/";
$ppu->extensions = "";
$ppu->formName = "replace_doc";
$ppu->storeType = "file";
$ppu->sizeLimit = "";
$ppu->nameConflict = "over";
$ppu->requireUpload = "true";
$ppu->minWidth = "";
$ppu->minHeight = "";
$ppu->maxWidth = "";
$ppu->maxHeight = "";
$ppu->saveWidth = "";
$ppu->saveHeight = "";
$ppu->timeout = "600";
$ppu->progressBar = "../blueFlashProgress.htm";
$ppu->progressWidth = "300";
$ppu->progressHeight = "100";
$ppu->redirectURL = "";
$ppu->checkVersion("2.1.7");
$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";
}
 
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 (!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;
}
}
 
 
$colname_condo_doc = "-1";
if (isset($_GET['id'])) {
  $colname_condo_doc = $_GET['id'];
}
 
mysql_select_db($database_boulders, $boulders);
$query_condo_doc = sprintf("SELECT * FROM condo_docs2 WHERE id = %s", GetSQLValueString($colname_condo_doc, "int"));
$condo_doc = mysql_query($query_condo_doc, $boulders) or die(mysql_error());
$row_condo_doc = mysql_fetch_assoc($condo_doc);
$totalRows_condo_doc = mysql_num_rows($condo_doc);
?><!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><?= $SITE_TITLE ?></title>
<link href="../admin.css" rel="stylesheet" type="text/css" />
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
</head>
 
 
<body>
<? include("../nav.php") ?>
<? include("nav2.php") ?>
<div id="wrapper_sub">
<br />
 
 
 <p>Use this form to replace an already exisiting document with an updated version.</p>
<p>Uploading will replace the document <strong><?php echo $row_condo_doc['file_url']; ?></strong>. It is identified with the link text of <strong><?php echo $row_condo_doc['name']; ?></strong> in the category of <?php if ($row_condo_docs['category'] == 0) {
	echo '<strong>Rules, Regulations</strong>';
	}
	elseif ($row_condo_docs['category'] == 1) {
	echo '<strong>Other Docs</strong>';
	}  ?>.</p>
<fieldset>
<legend>Replace Condo Doc</legend>
<div>
<h2>
  <?php
//if ((isset($_POST["MM_update"])) && ($_POST["MM_update"])) {
if (isset($_POST['Submit'])){
 
 $uploadLocation = "/home/content/s/h/o/shockoe/html/communities/boulders/";
 
 //converting upfile array name variable to a single variable
 $filenm=$_FILES['upfile']['name'];
	
 //converts spaces in filenames to underscore - from http://www.phpit.net/code/filename-safe/
 $filename=preg_replace ('/ {1,}/', '_', trim ($filenm));
	
 //the sql update statement converted to a variable
 $updateSQL = sprintf("UPDATE condo_docs2 SET `date`=%s, `file_url`=%s WHERE id=%s",
                       GetSQLValueString($_POST['date'], "date"),
                       GetSQLValueString($filename, "text"),
					   GetSQLValueString($_POST['id'], "int"));
 
  mysql_select_db($database_boulders, $boulders);
  $Result1 = mysql_query($updateSQL, $boulders) or die(mysql_error());
?>
    </h2>
<div id="caption">RESULT</div>
      <div id="icon2">&nbsp;</div>
      <div id="result">
        <table width="100%">
<?php
 
//vreating target path variable
 
$target_path = $uploadLocation . basename($filename);
echo $target_path;
 
//moving file from tmp to  upload directory
if(move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path)) {
    
	//response after execution
	echo "<p>The file: ".  basename( $_FILES['upfile']['name']).
    " has been uploaded!</p> ";
	
	echo "<p>Thank you for your submission.</p>";
	echo "<p>Click here to <a href=\"condos_aa.php\">return to the form Condo Docs Upload Form</a>.</p>";
 
	echo "<p>Close the window to Log out.</p>";
} else{
    echo "There was an error uploading the file, please try again!";
	echo 'Here is some more debugging info:';
print_r($_FILES);
}
 
?>
        </table>
     </div>
  <?php  } else {
 
 
?>
<form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="replace_doc" id="replace_doc" onsubmit="checkFileUpload(this,'',true,'','','','','','','');showProgressWindow('blueFlashProgress.htm',300,100);return document.MM_returnValue">
 
  <p>
    <input name="date" type="hidden" value="<?php $today = date("Ymd"); echo $today; ?>" />
    <input name="id" type="hidden" value="<?php echo $_GET['id']; ?>" />
    <input name="upfile" type="file" id="upfile" onchange="checkOneFileUpload(this,'',true,'','','','','','','')" />
    <br />
    <br />
    <input type="submit" name="Submit" id="Submit" value="Submit" />
  </p>
  <input type="hidden" name="MM_update" value="replace_doc" />
</form>
</fieldset>
<?php } ?>
</div>
 
</body>
</html>
<?php
mysql_free_result($condo_doc);
?>

Open in new window

0
 
LVL 20

Expert Comment

by:NerdsOfTech
ID: 24264208
Make sure that the file size of the file you're uploading is under the max upload size. You can change the allowed file size on the php.ini file. The default value is 2M (M as in Megabytes). Also make sure that uploading is allowed

Test with a really small file

Here's a 310 byte image file to test

;)
1x1pixelblue.jpg
0
 
LVL 20

Expert Comment

by:NerdsOfTech
ID: 24264250
php.ini
======

upload_max_filesize = 10M ;
post_max_size = 20M ;



.htaccess
=======

php_value upload_max_filesize 10M
 php_value post_max_size 20M
0
 
LVL 20

Expert Comment

by:NerdsOfTech
ID: 24264267
Let me know if the blue image can be uploaded (or any file under 2MB can be) first.

If it is successful it may be a size limit issue.

If not, then it is probably a permission issue.

Thanks
0
 

Author Comment

by:kentcommunications
ID: 24264464
I tested using the 1x1 image, which is a little smaller than the file I was using, but still no luck.

This web application has multiple pages where files (of sizes up to 10 MB) are uploaded to the same folder, and the results are printed in the same fashion.

On all the other pages, it is not updating a previously set record, it is adding a brand new one. The if...else statement regarding the error message display is exactly the same on all the files, and they don't show the error message when there is not an error.

I appreciate all your help so far! I've been testing a few items through trial and error, but I am on the lower-end of php programming, trying to learn more, so it's probably something small that I just don't recognize as being wrong!
0
 
LVL 20

Expert Comment

by:NerdsOfTech
ID: 24266475
Very interesting.

Please answer these questions:

1.) Is the record correctly being updated / inserted?
2.) Is the image being uploaded or not uploaded to the directory?
3.) What is the output of the page after to submitting your form page.

Thanks!
0
 

Author Comment

by:kentcommunications
ID: 24269538
1.) Is the record correctly being updated / inserted?
Yes

2.) Is the image being uploaded or not uploaded to the directory?
It's correctly being uploaded to the directory

3.) What is the output of the page after to submitting your form page.
Attached below.
<!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>Shockoe Properties</title>
<link href="../admin.css" rel="stylesheet" type="text/css" />
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
 
</head>
 
 
<body>
<div id="mainnav">
<a href="/admin/?logout=true">Logout</a> &#8226; 
<a href="/admin/properties.php">Properties</a> &#8226; 
<a href="/admin/apartments.php">Apartments</a> &#8226; 
<a href="/admin/condos.php">Condos</a>
</div>
<div id="mainnav">
 
<a href="condos.php">Add Minutes</a> &#8226; 
<a href="condos_aa.php">Add Documents</a> &#8226; 
<a href="condos_aa_directory.php">Organize Documents</a> &#8226; 
<a href="announcements.php">Add/Update Announcements</a>
</div><div id="wrapper_sub">
<br />
 
 
 <p>Use this form to replace an already exisiting document with an updated version.</p>
<p>Uploading will replace the document <strong>1x1pixelblue.jpg</strong>. It is identified with the link text of <strong>testter</strong> in the category of <strong>Rules, Regulations</strong>.</p>
 
<fieldset>
<legend>Replace Condo Doc</legend>
<div>
<h2>
      </h2>
<div id="caption">RESULT</div>
      <div id="icon2">&nbsp;</div>
      <div id="result">
        <table width="100%">
/home/content/s/h/o/shockoe/html/communities/boulders/blank.jpgThere was an error uploading the file, please try again!Here is some more debugging info:Array
(
    [upfile] => Array
        (
            [name] => blank.jpg
            [type] => image/jpeg
            [tmp_name] => /tmp/phpWrsX9x
            [error] => 0
            [size] => 19399
        )
 
)
        </table>
 
     </div>
  </div>
 
</body>
</html>

Open in new window

0
 

Author Comment

by:kentcommunications
ID: 24269575
I'm also attaching one of the working pages. This page is where they originally upload a document and it makes a record in the database. The page I'm having problems with is where the user can change the currently uploaded file (ie: if the terms of service changes).
<?php require_once('../../ScriptLibrary/incPureUpload.php'); ?>
<?php
 
if (!isset($_SESSION)) {
  session_start();
  
?>
<?php
// Pure PHP Upload 2.1.3
if (isset($HTTP_GET_VARS['GP_upload'])) {
	$ppu = new pureFileUpload();
	$ppu->path = "/web/communities/boulders/";
	$ppu->extensions = "";
	$ppu->formName = "condo_docs";
	$ppu->storeType = "file";
	$ppu->sizeLimit = "";
	$ppu->nameConflict = "over";
	$ppu->requireUpload = "true";
	$ppu->minWidth = "";
	$ppu->minHeight = "";
	$ppu->maxWidth = "";
	$ppu->maxHeight = "";
	$ppu->saveWidth = "";
	$ppu->saveHeight = "";
	$ppu->timeout = "600";
	$ppu->progressBar = "../blueFlashProgress.htm";
	$ppu->progressWidth = "300";
	$ppu->progressHeight = "100";
	$ppu->checkVersion("2.1.3");
	$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";
}
 
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";
  }
}
 
//error_reporting(E_ALL);
 require_once('../../Connections/boulders.php'); 
 include("../chkuser.php") ?>
<? include("../admin.php") ?>
<?
      $db = openConn();
 
}
?>
 
 
 
<!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><?= $SITE_TITLE ?></title>
<link href="../admin.css" rel="stylesheet" type="text/css" />
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
</head>
 
<body>
 
<? include("../nav.php") ?>
<? include("nav2.php") ?>
<div id="wrapper_sub">
<div>
 
</div>
 
<div>
<h2>
  <?php
//if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "condo_min")) {
if (isset($_POST['Submit'])){
 
//$uploadLocation = "/home/content/h/o/w/howellpt/html/ma_uploads/";
$uploadLocation = "/home/content/s/h/o/shockoe/html/communities/boulders/";
 
 
 
	//converting upfile array name variable to a single variable
	$filenm=$_FILES['upfile']['name'];
	
	//converts spaces in filenames to underscore - from http://www.phpit.net/code/filename-safe/
	 $filename=preg_replace ('/ {1,}/', '_', trim ($filenm));
	
	$selYear=$_POST['year_sel'];
	$mnthDay=$_POST['month_day'];
	
 /* $insertSQL = sprintf("INSERT INTO condo_docs ( `year`, month_day, pdf_link) VALUES (%s, %s, %s)",
                       GetSQLValueString($_POST['year_sel'], "text"),
                       GetSQLValueString($_POST['month_day'], "text"),
					   GetSQLValueString($_FILES['upfile']['name'], "text"));
 
  mysql_select_db($database_boulders, $boulders);
  $Result1 = mysql_query($insertSQL, $boulders) or die(mysql_error());
*/
 
 
	//the sql update statement converted to a variable
   $insertSQL = "INSERT INTO condo_docs2 (category, name, file_url, `date`, status) VALUES ('$_POST[category]', '$_POST[name]', 'communities/boulders/$filename', '$_POST[date]', '$_POST[status]')";                   
 //connect to database and perform update
 mysql_select_db($database_boulders, $boulders);
 $Result1 = mysql_query($insertSQL, $boulders) or die(mysql_error());
  
	
 
?>
    </h2>
<div id="caption">RESULT</div>
      <div id="icon2">&nbsp;</div>
      <div id="result">
        <table width="100%">
<?php
 
//vreating target path variable
 
$target_path = $uploadLocation . basename( $filename);
 
//moving file from tmp to  upload directory
if(move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path)) {
    
	//response after execution
	echo "<p>The file: ".  basename( $_FILES['upfile']['name']).
    " has been uploaded!</p> ";
	
	echo "<p>Thank you for your submission.</p>";
	echo "<p>Click here to <a href=\"condos_aa.php\">return to the form Condo Docs Upload Form</a>.</p>";
 
	echo "<p>Close the window to Log out.</p>";
} else{
    echo "There was an error uploading the file, please try again!";
	echo 'Here is some more debugging info:';
print_r($_FILES);
}
 
?>
        </table>
     </div>
  <?php  } else {
 
 
?>
 
<form method="post" enctype="multipart/form-data" name="condo_docs" id="condo_docs" onsubmit="checkFileUpload(this,'',true,'','','','','','','');showProgressWindow('../blueFlashProgress.htm',300,100);return document.MM_returnValue">
<fieldset>
<legend><strong>Add Docs</strong></legend>
<table width="600"  border="0" cellpadding="0" cellspacing="5">
  <tr>
    <td width="50%" align="right" valign="top"><input name="date" type="hidden" value="<?php $today = date("Ymd"); echo $today; ?>" /></td>
    <td width="50%"><input name="status" type="hidden" id="status" value="1" /></td>
  </tr>
  <tr>
    <td align="right" valign="top">Document Catagory</td>
    <td><select name="category" id="category">
      <option selected="selected">Choose</option>
      <option value="0">Rules, Regulations, etc</option>
      <option value="1">Other Documents</option>
    </select></td>
  </tr>
  <tr>
    <td width="50%" align="right" valign="top">Link Text </td>
    <td width="50%">
      <input name="name" type="text" id="name" size="15" maxlength="100" /></td>
  </tr>
  <tr>
    <td align="right" valign="top">Choose File to upload <br /></td>
    <td align="left"><input name="upfile" type="file" id="upfile" onchange="checkOneFileUpload(this,'',true,'','','','','','','')" size="24" maxlength="200" /></td>
  </tr>
  <tr>
    <td colspan="2"><input type="submit" name="Submit" value="Upload" /></td>
    </tr>
</table>
</fieldset>
 
<input type="hidden" name="MM_insert" value="condo_min" />
</form>
<?
}
?>
 </div>
 
 
</div>
 
</body>
</html>
<?
      closeConn($db);
?>

Open in new window

0
 
LVL 20

Expert Comment

by:NerdsOfTech
ID: 24272266
Okay I think I got it. Will post.
0
 
LVL 20

Expert Comment

by:NerdsOfTech
ID: 24272315
Try this and let me know if this works.
<?php require_once('../../Connections/boulders.php'); ?>
<?php require_once('../../ScriptLibrary/incPureUpload.php'); ?>
<?php include("../admin.php"); include("../chkuser.php") ?>
<?php
// Pure PHP Upload 2.1.7
$ppu = new pureFileUpload();
$ppu->path = "/home/content/s/h/o/shockoe/html/communities/boulders/";
$ppu->extensions = "";
$ppu->formName = "replace_doc";
$ppu->storeType = "file";
$ppu->sizeLimit = "";
$ppu->nameConflict = "over";
$ppu->requireUpload = "true";
$ppu->minWidth = "";
$ppu->minHeight = "";
$ppu->maxWidth = "";
$ppu->maxHeight = "";
$ppu->saveWidth = "";
$ppu->saveHeight = "";
$ppu->timeout = "600";
$ppu->progressBar = "../blueFlashProgress.htm";
$ppu->progressWidth = "300";
$ppu->progressHeight = "100";
$ppu->redirectURL = "";
$ppu->checkVersion("2.1.7");
$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";
}
 
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 (!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;
}
}
 
 
$colname_condo_doc = "-1";
if (isset($_GET['id'])) {
  $colname_condo_doc = $_GET['id'];
}
 
mysql_select_db($database_boulders, $boulders);
$query_condo_doc = sprintf("SELECT * FROM condo_docs2 WHERE id = %s", GetSQLValueString($colname_condo_doc, "int"));
$condo_doc = mysql_query($query_condo_doc, $boulders) or die(mysql_error());
$row_condo_doc = mysql_fetch_assoc($condo_doc);
$totalRows_condo_doc = mysql_num_rows($condo_doc);
?><!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><?= $SITE_TITLE ?></title>
<link href="../admin.css" rel="stylesheet" type="text/css" />
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
<script language='JavaScript' src='../../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
</head>
 
 
<body>
<? include("../nav.php") ?>
<? include("nav2.php") ?>
<div id="wrapper_sub">
<br />
 
 
 <p>Use this form to replace an already exisiting document with an updated version.</p>
<p>Uploading will replace the document <strong><?php echo $row_condo_doc['file_url']; ?></strong>. It is identified with the link text of <strong><?php echo $row_condo_doc['name']; ?></strong> in the category of <?php if ($row_condo_docs['category'] == 0) {
	echo '<strong>Rules, Regulations</strong>';
	}
	elseif ($row_condo_docs['category'] == 1) {
	echo '<strong>Other Docs</strong>';
	}  ?>.</p>
<fieldset>
<legend>Replace Condo Doc</legend>
<div>
<h2>
  <?php
//if ((isset($_POST["MM_update"])) && ($_POST["MM_update"])) {
if (isset($_POST['Submit'])){
 
 $uploadLocation = "/home/content/s/h/o/shockoe/html/communities/boulders/";
 
 //converting upfile array name variable to a single variable
 $filenm=$_FILES['upfile']['name'];
	
 //converts spaces in filenames to underscore - from http://www.phpit.net/code/filename-safe/
 $filename=preg_replace ('/ {1,}/', '_', trim ($filenm));
	
 //the sql update statement converted to a variable
 $updateSQL = sprintf("UPDATE condo_docs2 SET `date`=%s, `file_url`=%s WHERE id=%s",
                       GetSQLValueString($_POST['date'], "date"),
                       GetSQLValueString($filename, "text"),
					   GetSQLValueString($_POST['id'], "int"));
 
  mysql_select_db($database_boulders, $boulders);
  $Result1 = mysql_query($updateSQL, $boulders) or die(mysql_error());
?>
    </h2>
<div id="caption">RESULT</div>
      <div id="icon2">&nbsp;</div>
      <div id="result">
        <table width="100%">
<?php
 
//creating target path variable
 
$target_path = $uploadLocation . basename($filename);
 
//moving file from tmp to  upload directory
move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path);
 
//find if file exist
if (file_exists($targetpath)){
    
	//response after execution
	echo "<p>The file: ".  basename( $_FILES['upfile']['name']).
    " has been uploaded!</p> ";
	
	echo "<p>Thank you for your submission.</p>";
	echo "<p>Click here to <a href=\"condos_aa.php\">return to the form Condo Docs Upload Form</a>.</p>";
 
	echo "<p>Close the window to Log out.</p>";
} else{
    echo "There was an error uploading the file, please try again!";
	echo 'Here is some more debugging info:';
print_r($_FILES);
}
 
?>
        </table>
     </div>
  <?php  } else {
 
 
?>
<form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="replace_doc" id="replace_doc" onsubmit="checkFileUpload(this,'',true,'','','','','','','');showProgressWindow('blueFlashProgress.htm',300,100);return document.MM_returnValue">
 
  <p>
    <input name="date" type="hidden" value="<?php $today = date("Ymd"); echo $today; ?>" />
    <input name="id" type="hidden" value="<?php echo $_GET['id']; ?>" />
    <input name="upfile" type="file" id="upfile" onchange="checkOneFileUpload(this,'',true,'','','','','','','')" />
    <br />
    <br />
    <input type="submit" name="Submit" id="Submit" value="Submit" />
  </p>
  <input type="hidden" name="MM_update" value="replace_doc" />
</form>
</fieldset>
<?php } ?>
</div>
 
</body>
</html>
<?php
mysql_free_result($condo_doc);
?>
 
 
 
if (file_exists($targetpath) { //file exists
move_uploaded_file($_FILES['file1']['tmp_name'], 'my_temp_file_path/' . uniqid(rand()));
//decide here how to associate that file with the right person.
//perhaps use a session variable, or a hidden field containing the name of the new temp file
//output the file name exists and display new form
} else { //file doesnt exist
move_uploaded_file($_FILES['file1']['tmp_name'], 'my_file_path/' . $_FILES['file1']['name']);
}

Open in new window

0
 

Author Comment

by:kentcommunications
ID: 24273674
The code you provided did not fix the problem...but it did make me realize what the problem was!

The variable, $targetpath, in the IF clause, did not have an underscore in it.

/facepalm

But thank you for all the help! Points will be awarded momentarily :)


<?php
 
//creating target path variable
 
$target_path = $uploadLocation . basename($filename);
 
//moving file from tmp to  upload directory
move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path);
 
//find if file exist
// if (file_exists($targetpath)){
if (file_exists($target_path)){
    
	//response after execution
	echo "<p>The file: ".  basename( $_FILES['upfile']['name']).
    " has been uploaded!</p> ";
	
	echo "<p>Thank you for your submission.</p>";
	echo "<p>Click here to <a href=\"condos_aa.php\">return to the form Condo Docs Upload Form</a>.</p>";
 
	echo "<p>Close the window to Log out.</p>";
} else{
    echo "There was an error uploading the file, please try again!";
	echo 'Here is some more debugging info:';
print_r($_FILES);
}
 
?>

Open in new window

0
 

Author Closing Comment

by:kentcommunications
ID: 31575600
I really appreciate all your help, thank yo very much!  I'm so happy to see it fixed!
0
 
LVL 20

Expert Comment

by:NerdsOfTech
ID: 24274092
Oops Thanks for the correction and the points :)

Let me know if you need any more assistance.

=NerdsOfTech

0

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month19 days, 13 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question