Smart Image Processor PHP 2 Support Product Page

Error - SIP trying to resize the wrong form field

Reported 06 Dec 2010 18:22:12
1
has this problem
06 Dec 2010 18:22:12 Bruce Wilkie posted:
Hi There

Running:
PHP Pure Upload 2.1.10
SIP PHP 2.0.7
Vindows Vista Ultimate (SP2)
DW CS4 - Version 10 Build 4117

I'm trying to upload a document (eg pdf) and an image for a news item (code below). Both should go into the same folder on the server and the image needs to be resized.

When testing this page, the following occurs:

Option 1
If I select an image file for the picture field but no document file for the document field, it uploads and resizes the image fine.

Option 2
If I select a document file for the document field but no image file for the picture field then the document name is added to the database, but the document file doesn't get uploaded to the folder on the server.

Option 3
If I select an image for the picture field and a pdf (or word doc) for the document field, then the image uploads and resizes, the document name is added to the database, but the document file doesn't get uploaded to the folder on the server.

Option 3 - variation
If I select an image for the picture field and another image (not a pdf or word doc) for the document field, then the image in the image field uploads and resizes, PLUS the image file in the document field also uploads and also gets resized.


In summary, what appears to be happening is that the script is trying to resize both files and when there is a document file specified, then it adds it to the site's database, tries to resize it, fails because it's not an image, and so doesn't upload it to the server (without generating any errors on-screen)

Code for page plus scripts reproduced below:

(Note smilies have replaced some of the characters when I include my code. That wasn't me trying to inject humor into this cry for help. honest)

<?php require_once('../Connections/fahreendaleconnection.php'); ?>
<?php require_once('../ScriptLibrary/incPureUpload.php'); ?>
<?php require_once('../ScriptLibrary/cGraphicMediator.php'); ?>
<?php
// Pure PHP Upload 2.1.10
$ppu = new pureFileUpload();
$ppu->path = "../images/newspics/";
$ppu->extensions = "";
$ppu->formName = "insertnews";
$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 = "";
$ppu->progressWidth = "300";
$ppu->progressHeight = "100";
$ppu->redirectURL = "";
$ppu->checkVersion("2.1.10");
$ppu->doUpload();

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($editFormAction)) {
  if (isset($_SERVER['QUERY_STRING'])) {
	  if (!eregi("GP_upload=true", $_SERVER['QUERY_STRING'])) {
  	  $editFormAction .= "&GP_upload=true";
		}
  } else {
    $editFormAction .= "?GP_upload=true";
  }
}

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;
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "insertnews")) {
  
	$formdaynumber = $_POST['day'];
	$formmonth = $_POST['month'];
	$formyear = $_POST['year'];
	$formdate = $formyear."-".$formmonth."-".$formdaynumber;
	
	$insertSQL = sprintf("INSERT INTO tha_news (newsheadline, newsdate, newsdetails, newspic, newspiccaption, newsdownload, newsdownloadtext) VALUES (%s, '$formdate', %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['newsheadline'], "text"),
                       GetSQLValueString($_POST['newsdetails'], "text"),
                       GetSQLValueString($_POST['newspic'], "text"),
                       GetSQLValueString($_POST['newspiccaption'], "text"),
                       GetSQLValueString($_POST['newsdownload'], "text"),
                       GetSQLValueString($_POST['newsdownloadtext'], "text"));

  mysql_select_db($database_fahreendaleconnection, $fahreendaleconnection);
  $Result1 = mysql_query($insertSQL, $fahreendaleconnection) or die(mysql_error());

  $insertGoTo = "news.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_fahreendaleconnection, $fahreendaleconnection);
$query_rsnews = "SELECT *, date_format(newsdate,'%d/%m/%Y') as fDate FROM tha_news ORDER BY newsdate DESC";
$rsnews = mysql_query($query_rsnews, $fahreendaleconnection) or die(mysql_error());
$row_rsnews = mysql_fetch_assoc($rsnews);
$totalRows_rsnews = mysql_num_rows($rsnews);

mysql_select_db($database_fahreendaleconnection, $fahreendaleconnection);
$query_rsdaynumber = "SELECT * FROM fahreendaleha_daynumber ORDER BY daynumber ASC";
$rsdaynumber = mysql_query($query_rsdaynumber, $fahreendaleconnection) or die(mysql_error());
$row_rsdaynumber = mysql_fetch_assoc($rsdaynumber);
$totalRows_rsdaynumber = mysql_num_rows($rsdaynumber);

mysql_select_db($database_fahreendaleconnection, $fahreendaleconnection);
$query_rsmonth = "SELECT * FROM fahreendaleha_month ORDER BY monthid ASC";
$rsmonth = mysql_query($query_rsmonth, $fahreendaleconnection) or die(mysql_error());
$row_rsmonth = mysql_fetch_assoc($rsmonth);
$totalRows_rsmonth = mysql_num_rows($rsmonth);

mysql_select_db($database_fahreendaleconnection, $fahreendaleconnection);
$query_rsyear = "SELECT * FROM fahreendaleha_year ORDER BY `year` ASC";
$rsyear = mysql_query($query_rsyear, $fahreendaleconnection) or die(mysql_error());
$row_rsyear = mysql_fetch_assoc($rsyear);
$totalRows_rsyear = mysql_num_rows($rsyear);
?>
<?php
// Smart Image Processor PHP 2.0.7
if (isset($_GET['GP_upload'])) {
$sipp2 = new cGraphicMediator("upload", $ppu, "newspic");
$sipp2->setComponent("GD2");
$sipp2->setMatteColor("#FFFFFF");
$sipp2->resize(340, 340, true);
$sipp2->overwrite = true;
$sipp2->saveJPEG(80);
$sipp2->process();
}
?>
<!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>
<link href="fahreendaleadmin.css" rel="stylesheet" type="text/css" />
<script type="text/JavaScript">
<!--
function GP_popupConfirmMsg(msg) { //v1.0
  document.MM_returnValue = confirm(msg);
}
//-->
</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>
[h1]Administration Area[/h1]
[h2]Edit News [/h2]
<p><a href="index.htm" title="back to main menu ">< back to main menu</a></p>
[h3]Insert News Item[/h3]
<form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="insertnews" id="insertnews" onsubmit="checkFileUpload(this,'',false,'','','','','','','');return document.MM_returnValue">
  <p>
	  <label for="newsheadline">Headline</label>
    <input name="newsheadline" type="text" class="longfield" id="newsheadline" />
  </p>
  <p>
    <label for="newsdetails">Details</label>
    <textarea name="newsdetails" id="newsdetails"></textarea>
</p>
<?php 
	$curr_day = date("d");
	$curr_month = date("n"); 
	$curr_year = date("Y");
?>
  <p>
		
    <label>Date </label>
    <select name="day" class="exempt" id="day">
      <?php
do {  
?>
      <option value="<?php echo $row_rsdaynumber['daynumber']?>"<?php if (!(strcmp($row_rsdaynumber['daynumber'], $curr_day))) {echo "selected=\"selected\"";} ?>><?php echo $row_rsdaynumber['daynumber']?></option>
      <?php
} while ($row_rsdaynumber = mysql_fetch_assoc($rsdaynumber));
  $rows = mysql_num_rows($rsdaynumber);
  if($rows > 0) {
      mysql_data_seek($rsdaynumber, 0);
	  $row_rsdaynumber = mysql_fetch_assoc($rsdaynumber);
  }
?>
    </select>
    <select name="month" class="exempt" id="month">
      <?php
do {  
?>
      <option value="<?php echo $row_rsmonth['monthid']?>"<?php if (!(strcmp($row_rsmonth['monthid'], $curr_month))) {echo "selected=\"selected\"";} ?>><?php echo $row_rsmonth['month']?></option>
      <?php
} while ($row_rsmonth = mysql_fetch_assoc($rsmonth));
  $rows = mysql_num_rows($rsmonth);
  if($rows > 0) {
      mysql_data_seek($rsmonth, 0);
	  $row_rsmonth = mysql_fetch_assoc($rsmonth);
  }
?>
    </select>
    <select name="year" id="year">
      <?php
do {  
?>
      <option value="<?php echo $row_rsyear['year']?>"<?php if (!(strcmp($row_rsyear['year'], $curr_year))) {echo "selected=\"selected\"";} ?>><?php echo $row_rsyear['year']?></option>
      <?php
} while ($row_rsyear = mysql_fetch_assoc($rsyear));
  $rows = mysql_num_rows($rsyear);
  if($rows > 0) {
      mysql_data_seek($rsyear, 0);
	  $row_rsyear = mysql_fetch_assoc($rsyear);
  }
?>
    </select>
  </p>
  <p>
    <label for="newspic">Picture</label>
    <input name="newspic" type="file" id="newspic" onchange="checkOneFileUpload(this,'',false,'','','','','','','')" />
  </p>
  <p>
    <label for="newspiccaption">Pic Caption</label>
    <input name="newspiccaption" type="text" class="longfield" id="newspiccaption" />
  </p>
  <p>
    <label for="newsdownload">Download</label>
    <input name="newsdownload" type="file" id="newsdownload" onchange="checkOneFileUpload(this,'',false,'','','','','','','')" />
  </p>
  <p>
    <label for="newsdownloadtext">Link Text</label>
    <input name="newsdownloadtext" type="text" class="longfield" id="newsdownloadtext" />
(eg. &quot;click to download report&quot;)</p>
  <p>
    <label for="Submit">Action</label>
    <input type="submit" name="Submit" value="Insert" id="Submit" />
    <input type="hidden" name="hiddenField" />
</p>
    <input type="hidden" name="MM_insert" value="insertnews">
</form>
<?php if ($totalRows_rsnews > 0) { // Show if recordset not empty ?>
  [h3]Current News Items[/h3][list]
    <?php do { ?>[*]<?php echo $row_rsnews['newsheadline']; ?> (<?php echo $row_rsnews['fDate']; ?>)   - <a href="newsedit.php?newsid=<?php echo $row_rsnews['newsid']; ?>">edit</a> | <a href="newsdelete.php?newsid=<?php echo $row_rsnews['newsid']; ?>" onclick="GP_popupConfirmMsg('Please click OK to confirm deletion');return document.MM_returnValue">delete</a> [/*]
      <?php } while ($row_rsnews = mysql_fetch_assoc($rsnews)); ?>[/list]
  <?php } // Show if recordset not empty ?>
</body>
</html>
<?php
mysql_free_result($rsnews);

mysql_free_result($rsdaynumber);

mysql_free_result($rsmonth);

mysql_free_result($rsyear);
?>


Please help if you can.

Thanks




Replies

Replied 07 Feb 2011 16:14:02
07 Feb 2011 16:14:02 Patrick Woldberg replied:
In version 2.0.8 of SIP this behavior will be fixed.

Reply to this topic