Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7972585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:54:28+00:00 2026-06-04T07:54:28+00:00

I have a file which can possibly be moved into either 2 places depending

  • 0

I have a file which can possibly be moved into either 2 places depending on which button the user clicked on a seperate page:

At the moment I have stated if the the file moves into ‘ImageFiles’ folder then move the folder and insert a database row.

But I want to also include that if the file hasn’t been uploaded into ‘ImageFiles’ folder, then delete database row using this code below:

$imagecancelsql = "DELETE FROM Image 
                   WHERE ImageFile = 'ImageFiles/".
                   mysql_real_escape_string($_FILES['fileImage']['name'])."'";
mysql_query($imagecancelsql);

Is this possible to do and if so how can it be written in the current if/else statement I have in the php script?

Below is php script:

<?php

session_start();


...//connect to DB

$result = 0;

if( is_file("ImageFiles/".$_FILES['fileImage']['name'])) {
$parts = explode(".",$_FILES['fileImage']['name']);
$ext = array_pop($parts);
$base = implode(".",$parts);
$n = 2;

while( is_file("ImageFiles/".$base."_".$n.".".$ext)) $n++;
$_FILES['fileImage']['name'] = $base."_".$n.".".$ext;

    move_uploaded_file($_FILES["fileImage"]["tmp_name"],
    "ImageFiles/" . $_FILES["fileImage"]["name"]);
    $result = 1;

    $imagesql = "INSERT INTO Image (ImageFile) 
    VALUES ('ImageFiles/".mysql_real_escape_string($_FILES['fileImage']['name'])."')";

    mysql_query($imagesql);

}
    else
      {
      move_uploaded_file($_FILES["fileImage"]["tmp_name"],
      "ImageFiles/" . $_FILES["fileImage"]["name"]);
      $result = 1;

        $imagesql = "INSERT INTO Image (ImageFile) 
        VALUES ('ImageFiles/".mysql_real_escape_string($_FILES['fileImage']['name'])."')";

mysql_query($imagesql);

      }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:54:30+00:00Added an answer on June 4, 2026 at 7:54 am

    If I’ve understood correctly, the following code should work as intended. If the file has been found, the new file will replce it and inserts a new entry to your database.
    If the file wasnt found, the database entry will be removed from you table.

    // Stores the final result
    // 0 = File wasnt uploaded and the row has been removed from table
    // 1 = File was uploaded and the row has added to the table
    $result = 0;
    if (is_file("ImageFiles/" . $_FILES['fileImage']['name'])) {
        move_uploaded_file($_FILES["fileImage"]["tmp_name"], "ImageFiles/" . $_FILES["fileImage"]["name"]);
    
        $imagesql = "INSERT INTO Image (ImageFile) VALUES ('ImageFiles/".mysql_real_escape_string($_FILES['fileImage']['name'])."')";
        mysql_query($imagesql);
    
        // Mark result as 1 - we have added the file to teh folder and a entry to the table
        $result = 1;
    } else {
        $imagecancelsql = "DELETE FROM Image WHERE ImageFile = 'ImageFiles/" . mysql_real_escape_string($_FILES['fileImage']['name'])."'";
        mysql_query($imagecancelsql);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JSON string (external file) which has an element which can either
I have a file which is combination of PHP and HTML. How can i
I have a file which may be in ASCII or UTF-8 format. I can
We have a part of our program which can save a diagnostic file for
can anyone help? I have a simple html file which i am filling via
I can have an initialization file in my home directory called .gdbinit which is
Can anyone help. I have an ASP.NET application which has a web.config file so
Please can someone help? I have the following code which uploads a file to
I have an array which holds a record from a CSV file. Can I
I have html file which shows panoramic view of a place. HTML file calls

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.