Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Duplicate File names

Explorer ,
Oct 31, 2011 Oct 31, 2011

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

TOPICS
Server side applications
708
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Oct 31, 2011 Oct 31, 2011

What is the primary key of the 'modern' table? Does 'imageName' have a unique index?

Translate
LEGEND ,
Oct 31, 2011 Oct 31, 2011

What is the primary key of the 'modern' table? Does 'imageName' have a unique index?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 01, 2011 Nov 01, 2011

I did give 'imageName' a unique Index, however, your post reminded me that there was already duplicate file names in the database when a gave it a unique index and that I never went back to check it worked!

So sorry to waste time basically!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 01, 2011 Nov 01, 2011
LATEST

No problem, not a waste of time.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines