Forums
This topic is locked
Delete file before updating
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><?php
// Pure PHP Upload 2.1.3
if (isset($HTTP_GET_VARS['GP_upload'])) {
$ppu = new pureFileUpload();
$ppu->path = "uploads/Resumes";
$ppu->extensions = "doc,rtf,pdf,txt";
$ppu->formName = "form1";
$ppu->storeType = "file";
$ppu->sizeLimit = "200";
$ppu->nameConflict = "uniq";
$ppu->requireUpload = "true";
$ppu->minWidth = "";
$ppu->minHeight = "";
$ppu->maxWidth = "";
$ppu->maxHeight = "";
$ppu->saveWidth = "";
$ppu->saveHeight = "";
$ppu->timeout = "600";
$ppu->progressBar = "";
$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";
}
// 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->sqldata = mysql_fetch_array($dbu_result);
$dbu->pathThumb = "uploads/Resumes";
$dbu->naming = "suffix";
$dbu->suffix = "$br_resume";
$dbu->checkVersion("1.0.5"
$dbu->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));
}
?>
<?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);
?> </font id=code></pre id=code>
big thanks in advance!!! - KB