GX-Bug #44594 » Solved_problem_with_invalid_email_attachment_when_the_same_file_is_uploaded_twice_.patch
src/GXEngine/Classes/CoreServices/Email/AttachmentsHandler.inc.php (revision ) | ||
---|---|---|
76 | 76 |
*/ |
77 | 77 |
public function uploadAttachment(EmailAttachmentInterface $attachment) |
78 | 78 |
{ |
79 |
$info = pathinfo((string)$attachment->getPath()); |
|
80 | 79 |
$name = ($attachment->getName() |
81 | 80 |
!== null) ? (string)$attachment->getName() : basename((string)$attachment->getPath()); |
81 |
$originalName = $name; |
|
82 | 82 |
$path = $this->uploadsDirPath . '/tmp/'; |
83 | 83 |
|
84 | 84 |
// Validate uploaded file. |
... | ... | |
88 | 88 |
$postfixCounter = 1; |
89 | 89 |
do |
90 | 90 |
{ |
91 |
$name = $info['filename'] . '-' . $postfixCounter . '.' . $info['extension']; |
|
91 |
if (strpos($name, '.') > -1) |
|
92 |
{ |
|
93 |
$name = preg_replace('/\.(?=[^.]*$)/', '-' . $postfixCounter . '.', $originalName); |
|
94 |
} |
|
95 |
else |
|
96 |
{ |
|
97 |
$name = $originalName . '-' . $postfixCounter; |
|
98 |
} |
|
92 | 99 |
$postfixCounter++; |
93 | 100 |
} |
94 | 101 |
while(file_exists($path . $name)); |
... | ... | |
97 | 104 |
// Copy file to uploads directory. |
98 | 105 |
if(!@copy((string)$attachment->getPath(false), $path . $name)) |
99 | 106 |
{ |
100 |
throw new Exception('Could not store uploaded file: ' . $attachment['name']);
|
|
107 |
throw new Exception('Could not store uploaded file: ' . (string)$attachment->getPath());
|
|
101 | 108 |
} |
102 | 109 |
|
103 | 110 |
// Return new email attachment instance. |