title: Renaming Files by adding a Suffix
body: <p>Can i change the name of the file, say an image for example which has name like '0124.jpg',
  before sending it to the server?</p>
  
  <pre><code>&lt;input id="f1" style="margin-bottom: 5px;" type="file"  name="f1" onchange="javascript:readURL_f1(this);"/&gt;
  &lt;input id="f2" style="margin-bottom: 5px;" type="file"  name="f1" onchange="javascript:readURL_f2(this);"/&gt;
  </code></pre>
  
  <p>If the file is uploaded from f1, then before sending to to server, the name should become pic1_[filename].jpg, instead of just sending the raw filename. 
  I don't want this to be done in server side because i think it might be complicated.</p>
  
  <p><strong>EDIT</strong> : Upload.php is my php file which uploads whatever in the file. So, its been a challenge for me. i can change the filename, but that gets changed in all the three uploads.
  for example i add an '_' for the incoming filename. Then, it gets changed to all filenames. 
  Anyway from clientside?</p>
  
  <p>my upload script: <a href="http://jsfiddle.net/F7qGL/" rel="nofollow">Upload.php</a></p>
  
  <p><strong>upload.php</strong></p>
  
  <pre><code>&lt;?php mysql_connect('localhost','root','phpmyadmin');
   $connected = mysql_select_db('image_Upload');
   ?&gt;
  &lt;noscript&gt;
  &lt;div align="center"&gt;&lt;a href="index.php"&gt;Go Back To Upload Form&lt;/a&gt;&lt;/div&gt;&lt;!-- If javascript is disabled --&gt;
  &lt;/noscript&gt;
  &lt;?php
  //If you face any errors, increase values of "post_max_size", "upload_max_filesize" and "memory_limit" as required in php.ini
   //Some Settings
  $ThumbSquareSize         = 200; //Thumbnail will be 200x200
  $BigImageMaxSize         = 500; //Image Maximum height or width
  $ThumbPrefix            = "thumb_"; //Normal thumb Prefix
  $DestinationDirectory    = 'uploads/'; //Upload Directory ends with / (slash)
  $Quality                 = 90;
  $id = 'm123';
  //ini_set('memory_limit', '-1'); // maximum memory!
  
  foreach($_FILES as $file)
  {
  // some information about image we need later.
  $ImageName         = $file['name'];
  $ImageSize         = $file['size'];
  $TempSrc         = $file['tmp_name'];
  $ImageType         = $file['type'];
  
  if (is_array($ImageName))
  {
      $c = count($ImageName);
  
      echo  '&lt;ul&gt;';
  
      for ($i=0; $i &lt; $c; $i++)
      {
  
          $processImage            = true;    
          $RandomNumber            = rand(0, 9999999999);  // We need same random name for both files.
  
          if(!isset($ImageName[$i]) || !is_uploaded_file($TempSrc[$i]))
          {
              echo '&lt;div class="error"&gt;Error occurred while trying to process &lt;strong&gt;'.$ImageName[$i].'&lt;/strong&gt;, may be file too big!&lt;/div&gt;'; //output error
          }
          else
          {
              //Validate file + create image from uploaded file.
              switch(strtolower($ImageType[$i]))
              {
                  case 'image/png':
                      $CreatedImage = imagecreatefrompng($TempSrc[$i]);
                      break;
                  case 'image/gif':
                      $CreatedImage = imagecreatefromgif($TempSrc[$i]);
                      break;
                  case 'image/jpeg':
                  case 'image/pjpeg':
                      $CreatedImage = imagecreatefromjpeg($TempSrc[$i]);
                      break;
                  default:
                      $processImage = false; //image format is not supported!
              }
              //get Image Size
              list($CurWidth,$CurHeight)=getimagesize($TempSrc[$i]);
  
              //Get file extension from Image name, this will be re-added after random name
              $ImageExt = substr($ImageName[$i], strrpos($ImageName[$i], '.'));
              $ImageExt = str_replace('.','',$ImageExt);
  
              //Construct a new image name (with random number added) for our new image.
              $NewImageName = $id.'_'.'pic'.($i+1).'.'.$ImageExt;
  
              //Set the Destination Image path with Random Name
              $thumb_DestRandImageName     = $DestinationDirectory.$ThumbPrefix.$NewImageName; //Thumb name
              $DestRandImageName             = $DestinationDirectory.$NewImageName; //Name for Big Image
  
              //Resize image to our Specified Size by calling resizeImage function.
              if($processImage &amp;&amp; resizeImage($CurWidth,$CurHeight,$BigImageMaxSize,$DestRandImageName,$CreatedImage,$Quality,$ImageType[$i]))
              {
                  //Create a square Thumbnail right after, this time we are using cropImage() function
                  if(!cropImage($CurWidth,$CurHeight,$ThumbSquareSize,$thumb_DestRandImageName,$CreatedImage,$Quality,$ImageType[$i]))
                      {
                          echo 'Error Creating thumbnail';
                      }
                      /*
                      At this point we have succesfully resized and created thumbnail image
                      We can render image to user's browser or store information in the database
                      For demo, we are going to output results on browser.
                      */
  
                      //Get New Image Size
                      list($ResizedWidth,$ResizedHeight)=getimagesize($DestRandImageName);
                      echo '&lt;table width="100%" border="0" cellpadding="4" cellspacing="0"&gt;';
                      echo '&lt;tr&gt;';
                      echo '&lt;td align="center"&gt;&lt;img src="uploads/'.$ThumbPrefix.$NewImageName.
                      '" alt="Thumbnail" height="'.$ThumbSquareSize.'" width="'.$ThumbSquareSize.'"&gt;&lt;/td&gt;';
                      echo '&lt;/tr&gt;&lt;tr&gt;';
                      echo '&lt;td align="center"&gt;&lt;img src="uploads/'.$NewImageName.
                      '" alt="Resized Image" height="'.$ResizedHeight.'" width="'.$ResizedWidth.'"&gt;&lt;/td&gt;';
                      echo '&lt;/tr&gt;';
                      echo '&lt;/table&gt;';
  
                      if(isset($id))
                      {
                          mysql_query("UPDATE imagetable SET ImageName='$DestRandImageName',ThumbName='$thumb_DestRandImageName',
                          ImgPath='uploads/' WHERE id='$id'");
  
                      }
                      else{
                          mysql_query("INSERT INTO imagetable (id, ImageName, ThumbName, ImgPath)
                          VALUES ('$id','$DestRandImageName', '$thumb_DestRandImageName', 'uploads/')");    
                      }
  
              }else{
  
                  echo '&lt;div class="error"&gt;Error occurred while trying to process &lt;strong&gt;'.$ImageName.
                  '&lt;/strong&gt;! Please check if file is supported&lt;/div&gt;';
              }
  
          }
  
      }
      echo '&lt;/ul&gt;';
      }
  }
  
  // This function will proportionally resize image
  function resizeImage($CurWidth,$CurHeight,$MaxSize,$DestFolder,$SrcImage,$Quality,$ImageType)
  {
      //Check Image size is not 0
      if($CurWidth &lt;= 0 || $CurHeight &lt;= 0)
      {
          return false;
      }
  
      //Construct a proportional size of new image
      $ImageScale          = min($MaxSize/$CurWidth, $MaxSize/$CurHeight);
      $NewWidth              = ceil($ImageScale*$CurWidth);
      $NewHeight             = ceil($ImageScale*$CurHeight);
  
      if($CurWidth &lt; $NewWidth || $CurHeight &lt; $NewHeight)
      {
          $NewWidth = $CurWidth;
          $NewHeight = $CurHeight;
      }
      $NewCanves     = imagecreatetruecolor($NewWidth, $NewHeight);
      // Resize Image
      if(imagecopyresampled($NewCanves, $SrcImage,0, 0, 0, 0, $NewWidth, $NewHeight, $CurWidth, $CurHeight))
      {
          switch(strtolower($ImageType))
          {
              case 'image/png':
                  imagepng($NewCanves,$DestFolder);
                  break;
              case 'image/gif':
                  imagegif($NewCanves,$DestFolder);
                  break;            
              case 'image/jpeg':
              case 'image/pjpeg':
                  imagejpeg($NewCanves,$DestFolder,$Quality);
                  break;
              default:
                  return false;
          }
      if(is_resource($NewCanves)) {
        imagedestroy($NewCanves);
      }
      return true;
      }
  
  }
  
  //This function corps image to create exact square images, no matter what its original size!
  function cropImage($CurWidth,$CurHeight,$iSize,$DestFolder,$SrcImage,$Quality,$ImageType)
  {     
      //Check Image size is not 0
      if($CurWidth &lt;= 0 || $CurHeight &lt;= 0)
      {
          return false;
      }
  
      if($CurWidth&gt;$CurHeight)
      {
          $y_offset = 0;
          $x_offset = ($CurWidth - $CurHeight) / 2;
          $square_size     = $CurWidth - ($x_offset * 2);
      }else{
          $x_offset = 0;
          $y_offset = ($CurHeight - $CurWidth) / 2;
          $square_size = $CurHeight - ($y_offset * 2);
      }
  
      $NewCanves     = imagecreatetruecolor($iSize, $iSize);    
      if(imagecopyresampled($NewCanves, $SrcImage,0, 0, $x_offset, $y_offset, $iSize, $iSize, $square_size, $square_size))
      {
          switch(strtolower($ImageType))
          {
              case 'image/png':
                  imagepng($NewCanves,$DestFolder);
                  break;
              case 'image/gif':
                  imagegif($NewCanves,$DestFolder);
                  break;            
              case 'image/jpeg':
              case 'image/pjpeg':
                  imagejpeg($NewCanves,$DestFolder,$Quality);
                  break;
              default:
                  return false;
          }
      if(is_resource($NewCanves)) {
        imagedestroy($NewCanves);  
      }
      return true;
  
      }
  
  
  
  
  }
  </code></pre>