Page MenuHomeIn-Portal Phabricator

D321.id808.diff
No OneTemporary

File Metadata

Created
Wed, Feb 26, 9:03 AM

D321.id808.diff

Index: core/units/helpers/upload_helper.php
===================================================================
--- core/units/helpers/upload_helper.php
+++ core/units/helpers/upload_helper.php
@@ -88,9 +88,11 @@
$filename = $this->fileHelper->ensureUniqueFilename($tmp_path, $filename);
$storage_format = $this->getStorageFormat($this->Application->GetVar('field'), $event);
- $this->moveUploadedFile($tmp_path . $filename);
- if ( $storage_format ) {
+ $file_path = $tmp_path . $filename;
+ $actual_file_path = $this->moveUploadedFile($file_path);
+
+ if ( $storage_format && $file_path == $actual_file_path ) {
$this->resizeUploadedFile($tmp_path . $filename, $storage_format);
}
@@ -233,17 +235,18 @@
*
* @param string $file_path File path.
*
- * @return void
+ * @return string
* @throws kUploaderException When upload could not be handled properly.
*/
protected function moveUploadedFile($file_path)
{
- // Chunking might be enabled
+ // Chunking might be enabled.
$chunk = (int)$this->Application->GetVar('chunk', 0);
$chunks = (int)$this->Application->GetVar('chunks', 0);
+ $actual_file_path = $file_path . '.part';
- // Open temp file
- if ( !$out = @fopen("{$file_path}.part", $chunks ? 'ab' : 'wb') ) {
+ // Open temp file.
+ if ( !$out = @fopen($actual_file_path, $chunks ? 'ab' : 'wb') ) {
throw new kUploaderException('Failed to open output stream.', 102);
}
@@ -252,7 +255,7 @@
throw new kUploaderException('Failed to move uploaded file.', 103);
}
- // Read binary input stream and append it to temp file
+ // Read binary input stream and append it to temp file.
if ( !$in = @fopen($_FILES['file']['tmp_name'], 'rb') ) {
throw new kUploaderException('Failed to open input stream.', 101);
}
@@ -270,11 +273,14 @@
@fclose($out);
@fclose($in);
- // Check if file has been uploaded
+ // Check if file has been uploaded.
if ( !$chunks || $chunk == $chunks - 1 ) {
- // Strip the temp .part suffix off
- rename("{$file_path}.part", $file_path);
+ // Strip the temp .part suffix off.
+ rename($actual_file_path, $file_path);
+ $actual_file_path = $file_path;
}
+
+ return $actual_file_path;
}
/**

Event Timeline