diff --git a/file_entity.pages.inc b/file_entity.pages.inc index e9ae2b4..6c74536 100644 --- a/file_entity.pages.inc +++ b/file_entity.pages.inc @@ -461,8 +461,11 @@ function file_entity_add_upload_submit($form, &$form_state) { 'file_directory' => $form_state['storage']['path'], )) . $separator . drupal_basename($file->uri); + /* we need to make sure the file exists before we can move it */ + $exists = file_destination($file->uri, FILE_EXISTS_ERROR); + // If it changed, move the file to its new location. - if ($file->uri != $uri_new) { + if (($file->uri != $uri_new) && $exists) { $path = drupal_dirname($uri_new); file_prepare_directory($path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); $file = file_move($file, $uri_new, FILE_EXISTS_RENAME);