title: PDOException on Duplicate filename in Drupal 7
body: <p>Using the following code:</p>
  
  <pre><code>foreach ($form_state['values']['uploads'] as $key =&gt; $value) {
  if (strlen($value)) {
    $file = file_save_upload($key, array(
      'file_validate_is_image' =&gt; array(), // Validates file is really an image. 
      'file_validate_extensions' =&gt; array('png gif jpg jpeg'), // Validate extensions.
    ));
    // If the file passed validation:
    if ($file) {
      // Move the file, into the Drupal file system
      if ($file = file_move($file, 'public://')) {
       // Save the file for use in the submit handler.
       $form_state['values']['uploaded_photos'][] = $file;
               $x++;
      } else {
       form_set_error($key, t('Failed to write the uploaded file the site\'s file folder.'));
      }
    }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I am trying to save images attached to a form into a cached object with CTools. All of that was working fine, until I tried uploading the same file again, and I got a white screen that said "Error  - The website encountered an error." (ripped from watchdog):</p>
  
  <pre><code>SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'public://ad-10.jpg'; for key 2: UPDATE {file_managed} SET uid=:db_update_placeholder_0, filename=:db_update_placeholder_1, uri=:db_update_placeholder_2, filemime=:db_update_placeholder_3, filesize=:db_update_placeholder_4, status=:db_update_placeholder_5, timestamp=:db_update_placeholder_6
  WHERE  (fid = :db_condition_placeholder_0) ; Array
  (
  [:db_update_placeholder_0] =&amp;gt; 0
  [:db_update_placeholder_1] =&amp;gt; ad-10.jpg
  [:db_update_placeholder_2] =&amp;gt; public://ad-10.jpg
  [:db_update_placeholder_3] =&amp;gt; image/jpeg
  [:db_update_placeholder_4] =&amp;gt; 4912
  [:db_update_placeholder_5] =&amp;gt; 0
  [:db_update_placeholder_6] =&amp;gt; 1326221376
  [:db_condition_placeholder_0] =&amp;gt; 834
  )
  ";s:9:"%function";s:21:"drupal_write_record()";
  </code></pre>
  
  <p>Since I am not setting the $replace argument, shouldn't it default to FILE_EXISTS_RENAME and therefor not throw this error? How can I resolve this?</p>