Pure PHP Upload Add-On Pack Support Product Page

Delete before Update not working.

Asked 28 Apr 2010 02:05:40
1
has this question
28 Apr 2010 02:05:40 Armen M posted:
The new file gets uploaded and the name is updated in the database. However, the old file is not deleted.

=========

<?php require_once('../Connections/connData.php'); ?>
<?php require_once('../ScriptLibrary/incPureUpload.php'); ?>
<?php require_once('../ScriptLibrary/cGraphicMediator.php'); ?>
<?php require_once('../ScriptLibrary/incPUAddOn.php'); ?>
<?php
// Pure PHP Upload 2.1.10
$ppu = new pureFileUpload();
$ppu->path = "../uploads";
$ppu->extensions = "GIF,JPG,JPEG,BMP,PNG";
$ppu->formName = "form1";
$ppu->storeType = "file";
$ppu->sizeLimit = "";
$ppu->nameConflict = "uniq";
$ppu->requireUpload = "true";
$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->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;
}
}

// Delete Before Update Addon 1.0.7
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1" {
mysql_select_db($database_connData, $connData);
$dbu_result = mysql_query("SELECT * FROM tblListings WHERE ID=".$_POST['ID'] , $connData) or die(mysql_error());
$dbu = new deleteFileBeforeUpdate($ppu);
$dbu->pathThumb = "../uploads";
$dbu->naming = "prefix";
$dbu->suffix = "_thumb";
$dbu->checkVersion("1.0.7";
while ($dbu->sqldata = mysql_fetch_array($dbu_result)) {
$dbu->deleteFile();
}
}

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

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1" {
$updateSQL = sprintf("UPDATE tblListings SET itemImage=IFNULL(%s,itemImage) WHERE ID=%s",
GetSQLValueString($_POST['fileField'], "text",
GetSQLValueString($_POST['ID'], "int";

mysql_select_db($database_connData, $connData);
$Result1 = mysql_query($updateSQL, $connData) or die(mysql_error());

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

$colname_rsUpdate = "-1";
if (isset($_GET['ID'])) {
$colname_rsUpdate = $_GET['ID'];
}
mysql_select_db($database_connData, $connData);
$query_rsUpdate = sprintf("SELECT * FROM tblListings WHERE ID = %s", GetSQLValueString($colname_rsUpdate, "int";
$rsUpdate = mysql_query($query_rsUpdate, $connData) or die(mysql_error());
$row_rsUpdate = mysql_fetch_assoc($rsUpdate);
$totalRows_rsUpdate = mysql_num_rows($rsUpdate);
?>
<?php
// Smart Image Processor PHP 2.0.7
if (isset($_GET['GP_upload'])) {
$sipp2 = new cGraphicMediator("upload", $ppu, "";
$sipp2->setComponent("Auto";
$sipp2->setMatteColor("#FFFFFF";
$sipp2->resize(250, 175, true);
$sipp2->overwrite = false;
$sipp2->setMask("../uploads/thumb_##name##.jpg";
$sipp2->saveJPEG(80);
$sipp2->process();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<link href="css/main.css" rel="stylesheet" type="text/css" />
<script language='JavaScript' src='../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
</head>

<body>
<h1 align="center">Update Product Image</h1>
<p align="center">&nbsp;</p>
<form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="form1" id="form1" onsubmit="checkFileUpload(this,'GIF,JPG,JPEG,BMP,PNG',true,'','','','','','','');showProgressWindow('fileCopyProgress.htm',300,100);return document.MM_returnValue">
<table width="300" border="0" align="center" cellpadding="3" cellspacing="3">
<tr>
<td align="center"><input name="fileField" type="file" id="fileField" onchange="checkOneFileUpload(this,'GIF,JPG,JPEG,BMP,PNG',true,'','','','','','','')" /></td>
</tr>
<tr>
<td align="center"><p>
<input name="ID" type="hidden" id="ID" value="<?php echo $row_rsUpdate['ID']; ?>" />
</p>
<p>
<input type="submit" name="button" id="button" value="Update" />
</p></td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form1" />
</form>
<p align="center">&nbsp;</p>
<p align="center">&nbsp;</p>
<p align="center"><a href="javascript:window.close();">Close Window</a></p>
</body>
</html>
<?php
mysql_free_result($rsUpdate);
?>

Replies

Replied 29 Apr 2010 08:09:33
29 Apr 2010 08:09:33 Armen M replied:
Hello... anybody there?

I purchased this extension expecting it to work as described. I understand things can go wrong but not being able to contact anyone in support or get a response in the forum is ridiculous. Has anybody been able to chat with live support? I have never even seen it say 'online' it always seems to be 'offline'
Replied 29 Apr 2010 10:57:50
29 Apr 2010 10:57:50 Miroslav Zografski replied:
Hello Armen,

first check out your settings :
$dbu->naming = "prefix";
$dbu->suffix = "_thumb";
you have set Prefix and appointed a suffix.

Regards,
Replied 29 Apr 2010 19:42:19
29 Apr 2010 19:42:19 Armen M replied:
I noticed that myself. Here's what I did:
1. I removed the delete on update behavior
2. Applied the behavior again to make sure I'm doing it corectly
3. I selected prefix and entered thumb_

The same problem again. The database is updated and the new file uploaded. However, the old file is not deleted.

==========

Here is the new code:

<?php require_once('../Connections/connData.php'); ?>
<?php require_once('../ScriptLibrary/incPureUpload.php'); ?>
<?php require_once('../ScriptLibrary/cGraphicMediator.php'); ?>
<?php require_once('../ScriptLibrary/incPUAddOn.php'); ?>
<?php ?>
<?php
// Pure PHP Upload 2.1.10
$ppu = new pureFileUpload();
$ppu->path = "../uploads";
$ppu->extensions = "GIF,JPG,JPEG,BMP,PNG";
$ppu->formName = "form1";
$ppu->storeType = "file";
$ppu->sizeLimit = "";
$ppu->nameConflict = "uniq";
$ppu->requireUpload = "true";
$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->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;
}
}

// Delete Before Update Addon 1.0.7
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1") {
mysql_select_db($database_connData, $connData);
$dbu_result = mysql_query("SELECT * FROM tblListings WHERE ID=".$_POST['ID'] , $connData) or die(mysql_error());
$dbu = new deleteFileBeforeUpdate($ppu);
$dbu->pathThumb = "../uploads";
$dbu->naming = "prefix";
$dbu->suffix = "thumb_";
$dbu->checkVersion("1.0.7";
while ($dbu->sqldata = mysql_fetch_array($dbu_result)) {
$dbu->deleteFile();
}
}

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

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1") {
$updateSQL = sprintf("UPDATE tblListings SET itemImage=IFNULL(%s,itemImage) WHERE ID=%s",
GetSQLValueString($_POST['fileField'], "text",
GetSQLValueString($_POST['ID'], "int");

mysql_select_db($database_connData, $connData);
$Result1 = mysql_query($updateSQL, $connData) or die(mysql_error());

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

$colname_rsUpdate = "-1";
if (isset($_GET['ID'])) {
$colname_rsUpdate = $_GET['ID'];
}
mysql_select_db($database_connData, $connData);
$query_rsUpdate = sprintf("SELECT * FROM tblListings WHERE ID = %s", GetSQLValueString($colname_rsUpdate, "int");
$rsUpdate = mysql_query($query_rsUpdate, $connData) or die(mysql_error());
$row_rsUpdate = mysql_fetch_assoc($rsUpdate);
$totalRows_rsUpdate = mysql_num_rows($rsUpdate);
?>
<?php
// Smart Image Processor PHP 2.0.7
if (isset($_GET['GP_upload'])) {
$sipp2 = new cGraphicMediator("upload", $ppu, "";
$sipp2->setComponent("Auto";
$sipp2->setMatteColor("#FFFFFF";
$sipp2->resize(250, 175, true);
$sipp2->overwrite = false;
$sipp2->setMask("../uploads/thumb_##name##.jpg";
$sipp2->saveJPEG(80);
$sipp2->process();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<link href="css/main.css" rel="stylesheet" type="text/css" />
<script language='JavaScript' src='../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
</head>

<body>
<h1 align="center">Update Product Image</h1>
<p align="center">&nbsp;</p>
<form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="form1" id="form1" onsubmit="checkFileUpload(this,'GIF,JPG,JPEG,BMP,PNG',true,'','','','','','','');showProgressWindow('fileCopyProgress.htm',300,100);return document.MM_returnValue">
<table width="300" border="0" align="center" cellpadding="3" cellspacing="3">
<tr>
<td align="center"><input name="fileField" type="file" id="fileField" onchange="checkOneFileUpload(this,'GIF,JPG,JPEG,BMP,PNG',true,'','','','','','','')" /></td>
</tr>
<tr>
<td align="center"><p>
<input name="ID" type="hidden" id="ID" value="<?php echo $row_rsUpdate['ID']; ?>" />
</p>
<p>
<input type="submit" name="button" id="button" value="Update" />
</p></td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form1" />
</form>
<p align="center">&nbsp;</p>
<p align="center">&nbsp;</p>
<p align="center"><a href="javascript:window.close();">Close Window</a></p>
</body>
</html>
<?php
mysql_free_result($rsUpdate);
?>
Replied 29 Apr 2010 23:55:55
29 Apr 2010 23:55:55 Armen M replied:
I AM VERY FRUSTRATED WITH THIS USELESS EXTENSION. Judging by the many other posts regarding it, I'm not alone. I am very disappointed with the lack of support provided by DMXZONE. I've received better (and more timely) support for extensions that were free (not to mention the convenience of live support systems that actually are live as opposed to OFFLINE ALL THE TIME). After years of being a loyal customer and having suggested your extensions to countless individuals, i must say again that I AM EXTREMELY DISAPPOINTED. This comment is not directed to the many volunteers who share their expertise, but rather to whoever is taking the money and not providing the support.
Replied 30 Apr 2010 10:30:22
30 Apr 2010 10:30:22 Miroslav Zografski replied:
Hello Armen,

I'm sorry for the inconvenience.

We are already working to resolve and fix the issue.

Regards,
Replied 30 Apr 2010 12:57:08
30 Apr 2010 12:57:08 Miroslav Zografski replied:
Hello Armen,

The Extension expects the file upload field to be named after the name of the column where you record the filename - in your case - fileField should be renamed to itemImage. Also the input that you populate the id of the record in should be set to 'id' instead of 'ID'.

I'll see to the developer so in the future we figure more user friendly way of setting those.

Regards,

Reply to this topic