title: how to change the image name while storing in a folder via php
body: <p>i am working on a website, in which each user can upload multiple images..i am able to upload the image and storing in a folder but i have a problem when two different user have the same image name, as i am storing image in a single folder. In the database where ,i am storing information, serial no is the unique key..i want to rename the image with adding serial no. with the image name to make it unique...please help me..to do it..</p>
  
  <pre><code>my form is as:-
  
  &lt;form action="upload_file.php" method="post" enctype="multipart/form-data"&gt;
  &lt;input type="file" name="file" id="file" /&gt; &lt;/br&gt;&lt;br/&gt;
  &lt;input id="submit" type="submit" value="submit" /&gt;
  </code></pre>
  
  <p>and upload_file.php is as:-</p>
  
  <pre><code>require_once('dbconnect.inc.php');
  $db_name="uploaddata";
  $tbl_name="data";
  $db_selected=mysql_select_db("$db_name")or die("cannot select DB");
  if ((($_FILES["file"]["type"] == "image/gif")
      || ($_FILES["file"]["type"] == "image/jpeg")
      || ($_FILES["file"]["type"] == "image/pjpeg"))
      &amp;&amp; ($_FILES["file"]["size"] &gt; 0))
   {
    if ($_FILES["file"]["error"] &gt; 0)
      {
      echo "Return Code: " . $_FILES["file"]["error"] . "&lt;br /&gt;";
      }
    else
      {
      $Image_name=$_FILES["file"]["name"];
      $Image_type=$_FILES["file"]["type"];
       //upload is the folder of storing images       
       if (file_exists("upload/" . $_FILES["file"]["name"]))
        {
       $_SESSION['response'] = " already exists please give some different name ";
       header("Location: testimage.php");
        }
      else
        {
  
        move_uploaded_file($_FILES["file"]["tmp_name"],
        "upload/" . $_FILES["file"]["name"]);
               $login_data="INSERT INTO $tbl_name(Image_name,Image_type) VALUES('$Image_name','$Image_type')";
  
          $login_result=mysql_query($login_data) or die(mysql_error());
          header("Location: abc.php");
            }
      }
    }
  </code></pre>