Duplicate File names
Hi all,
Please find script below.
I'm trying to stop duplicate filenames. So if there is a file named the same as the one trying to uploaded already in the database it flags up as an error and doesn't process the upload script.
I thought the below would work but does not appear to at all, the photo upoads fine and data is posted to database but if I purposefully try to upload a file I lknow already exists, it overwrites the existing file.
Any thoughts?
Tom
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO modern (imageID, imageName, imageTitle, imageDescription) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['imageID'], "int"),
GetSQLValueString($_FILES['imageName']['name'], "text"),
GetSQLValueString($_POST['imageTitle'], "text"),
GetSQLValueString($_POST['imageDescription'], "text"));
mysql_select_db($database_connJohnnash, $connJohnnash);
$Result1 = mysql_query($insertSQL, $connJohnnash);
if (!$Result1 && mysql_errno() == 1062) {
$error['imageName'] = '<strong>' . $_FILES['imageName']['name'] . '.jpg </strong>is already in use and connot be overwritten. Please rename the image and try again.';
} elseif (mysql_error()) {
$error['dbError'] = 'Sorry, there was a problem with the databse. Please try again later.';
} else {
//Image Upload
//Set the maximum upload size in bytes
$max = 250000;
//define the path to upload folder
$destination = '../modern-images/';
require_once('../Ps2/Upload.php');
try {
$upload = new Ps2_Upload($destination);
$upload->move();
$result = $upload->getMessages();
} catch (Exception $e) {
echo $e->getMessage();
}
//End Image Upload - start processing the rest of the form
$insertGoTo = "view-modern.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
}
Message was edited by: sellador315
