--- D:/www.prevencionintegral.com/website/includes/file.inc	Wed Mar 05 17:39:30 2014
+++ D:/www.prevencionintegral.com/website/includes/file - Copy.inc	Wed Mar 05 18:52:08 2014
@@ -864,24 +864,22 @@
   // Build a destination URI if necessary.
   if (!isset($destination)) {
     $destination = file_build_uri(drupal_basename($source));
   }
 
-
-  // Prepare the destination directory.
-  if (file_prepare_directory($destination, FILE_CREATE_DIRECTORY)) {
-    // The destination is already a directory, so append the source basename.
-    $destination = file_stream_wrapper_uri_normalize($destination . '/' . drupal_basename($source));
-  }
-  else {
-    // Perhaps $destination is a dir/file?
-    $dirname = drupal_dirname($destination);
-    if (!file_prepare_directory($dirname, FILE_CREATE_DIRECTORY)) {
+  // file_prepare_directory does not distinguish between URI's that are
+  // filenames or plain paths, we must take care of that ourselves.
+  $dirname = drupal_dirname($destination);
+  if (!file_prepare_directory($dirname, FILE_CREATE_DIRECTORY)) {
       // The destination is not valid.
       watchdog('file', 'File %file could not be copied, because the destination directory %destination is not configured correctly.', array('%file' => $original_source, '%destination' => $dirname));
       drupal_set_message(t('The specified file %file could not be copied, because the destination directory is not properly configured. This may be caused by a problem with file or directory permissions. More information is available in the system log.', array('%file' => $original_source)), 'error');
       return FALSE;
+  } else {
+    if ($destination == $dirname) {
+      // The destination is already a directory, so append the source basename.
+      $destination = file_stream_wrapper_uri_normalize($destination . '/' . drupal_basename($source));
     }
   }
 
   // Determine whether we can perform this operation based on overwrite rules.
   $destination = file_destination($destination, $replace);
