Forums

PHP

This topic is locked

Delete file before updating

Posted 18 Aug 2004 05:45:01
1
has voted
18 Aug 2004 05:45:01 K B posted:
Seems like a common thing to want to do = if file exists, delete before uploading/updating record. From searching around I gather that I would use some sort of "unlink()" function, but as a php noob I'm lost to what it should look like and where to place it... Help please...????

My code: <pre id=code><font face=courier size=2 id=code>&lt;?php
// Pure PHP Upload 2.1.3
if (isset($HTTP_GET_VARS['GP_upload'])) {
$ppu = new pureFileUpload();
$ppu-&gt;path = "uploads/Resumes";
$ppu-&gt;extensions = "doc,rtf,pdf,txt";
$ppu-&gt;formName = "form1";
$ppu-&gt;storeType = "file";
$ppu-&gt;sizeLimit = "200";
$ppu-&gt;nameConflict = "uniq";
$ppu-&gt;requireUpload = "true";
$ppu-&gt;minWidth = "";
$ppu-&gt;minHeight = "";
$ppu-&gt;maxWidth = "";
$ppu-&gt;maxHeight = "";
$ppu-&gt;saveWidth = "";
$ppu-&gt;saveHeight = "";
$ppu-&gt;timeout = "600";
$ppu-&gt;progressBar = "";
$ppu-&gt;progressWidth = "300";
$ppu-&gt;progressHeight = "100";
$ppu-&gt;checkVersion("2.1.3";
$ppu-&gt;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";
}


// Delete Before Update Addon 1.0.5
if ((isset($HTTP_POST_VARS["MM_update"])) && ($HTTP_POST_VARS["MM_update"] == "undefined") {
mysql_select_db($database_chempharma, $chempharma);
$dbu_result = mysql_query("SELECT * FROM nuke_users WHERE pn_uid=".$HTTP_POST_VARS['pn_uid'] , $chempharma) or die(mysql_error());
$dbu = new deleteFileBeforeUpdate($ppu);
$dbu-&gt;sqldata = mysql_fetch_array($dbu_result);
$dbu-&gt;pathThumb = "uploads/Resumes";
$dbu-&gt;naming = "suffix";
$dbu-&gt;suffix = "$br_resume";
$dbu-&gt;checkVersion("1.0.5";
$dbu-&gt;deleteFile();
}

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

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

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 ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1") {
$updateSQL = sprintf("UPDATE nuke_users SET br_resume=IFNULL(%s,br_resume) WHERE pn_uid=%s",
GetSQLValueString($_POST['br_resume'], "text",
GetSQLValueString($_POST['pn_uid'], "int");

mysql_select_db($database_chempharma, $chempharma);
$Result1 = mysql_query($updateSQL, $chempharma) or die(mysql_error());

$updateGoTo = "modules.php?op=modload&name=Members&file=delete";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}

?&gt;
&lt;?php
mysql_select_db($database_chempharma, $chempharma);
$query_Resumes = "SELECT nuke_users.pn_uid, nuke_users.br_resume FROM nuke_users WHERE nuke_users.pn_uid = $pn_uid";
$Resumes = mysql_query($query_Resumes, $chempharma) or die(mysql_error());
$row_Resumes = mysql_fetch_assoc($Resumes);
$totalRows_Resumes = mysql_num_rows($Resumes);
?&gt; </font id=code></pre id=code>

big thanks in advance!!! - KB

Reply to this topic