Merge pull request #9575 from jitendrapurohit/CRM-19761
[civicrm-core.git] / api / v3 / Attachment.php
index e8917eb4836e51c8fbd62f92d1e27fdb29fce4c3..62402722f2f48fbbc9464bad89598ac88a19f2b6 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2015                                |
+ | Copyright CiviCRM LLC (c) 2004-2016                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -105,9 +105,8 @@ function _civicrm_api3_attachment_create_spec(&$spec) {
  * @see Civi\API\Subscriber\DynamicFKAuthorization
  */
 function civicrm_api3_attachment_create($params) {
-
   if (empty($params['id'])) {
-    // When creating we need either entity_table or field_name
+    // When creating we need either entity_table or field_name.
     civicrm_api3_verify_one_mandatory($params, NULL, array('entity_table', 'field_name'));
   }
 
@@ -160,7 +159,10 @@ function civicrm_api3_attachment_create($params) {
     file_put_contents($path, $content);
   }
   elseif (is_string($moveFile)) {
-    rename($moveFile, $path);
+    // CRM-17432 Do not use rename() since it will break file permissions.
+    // Also avoid move_uplaoded_file() because the API can use options.move-file.
+    copy($moveFile, $path);
+    unlink($moveFile);
   }
 
   // Save custom field to entity