title: Renaming an image during the uploading PHP Mysql
body: <p>Using the following code could someone explain to me how I can rename the image files to a misc name during the upload process? </p>
  
  <p>Here is what I'm working with.</p>
  
  <p><strong>uploader.php</strong> </p>
  
  <pre><code>&lt;?php
  include($_SERVER['DOCUMENT_ROOT'] . "/connections/dbconnect.php");
  $dataType = mysql_real_escape_string($_POST["dataType"]);
  $title = mysql_real_escape_string($_POST["title"]);
  $fileName = basename($_FILES["image"]["name"]);
  $target_path = ($_SERVER['DOCUMENT_ROOT'] . "/images/gallery/".$fileName);
  if (file_exists($target_path))
  {
      echo "An image with that file name already exists.";
  }
  elseif (move_uploaded_file($_FILES["image"]["tmp_name"], $target_path))
  {
      // The file is in the images/gallery folder. Insert record into database by
      // executing the following query:
       $sql="INSERT INTO images (data_type, title, file_name)"."VALUES('$dataType','$title','$fileName')";
       $retval = mysql_query($sql);
  
      echo "The image was successfully uploaded and added to the gallery :) &lt;a href='index.php'&gt;Add another image&lt;/a&gt;";
  
  
  }
  else
  {
      echo "There was an error uploading the file, please try again!";
  }
  ?&gt;
  </code></pre>
  
  <hr>
  
  <p>Then here is my code for uploading the image to the gallery.</p>
  
  <hr>
  
  <pre><code>&lt;form enctype="multipart/form-data" action="uploader.php" method="POST"&gt;
  
  
          Category: &lt;select class="text" name="dataType"&gt;
          &lt;option value="treeremoval" selected="selected"&gt;treeremoval&lt;/option&gt;
          &lt;option value="treetrimming" &gt;treetrimming&lt;/option&gt;
          &lt;option value="treebracing" &gt;treebracing&lt;/option&gt;
          &lt;option value="stumpgrinding" &gt;stumpgrinding&lt;/option&gt;
          &lt;option value="firewood" &gt;firewood&lt;/option&gt;
          &lt;option value="cleanup" &gt;cleanup&lt;/option&gt;
          &lt;/select&gt;&lt;br /&gt;
  &lt;br /&gt;
  
  
  
  
      Caption: &lt;input type="text" name="title"&gt;&lt;br /&gt;
  &lt;br /&gt;
  
      Image to upload: &lt;input type="file" name="image"&gt;&lt;br /&gt;
  &lt;br /&gt;
  
  
  
  
      &lt;input type="submit" value="Upload"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I am very new to using php and mysql so any help would be appreciated. I have some other questions too, but I guess I should ask one at a time. =)</p>
  
  <p>Thank You!</p>