Fix #17875: Revert move_uploaded_file() function instead of copy() and unlink() for saving uploaded files when POST request

This commit is contained in:
Yusup Hambali
2020-02-20 09:22:01 +00:00
committed by GitHub
parent 7ec7fd11ee
commit 55793471ea
4 changed files with 16 additions and 55 deletions

View File

@ -11,6 +11,8 @@ Yii Framework 2 Change Log
- Bug #17829: `yii\helpers\ArrayHelper::filter` now correctly filters data when passing a filter with more than 2 levels (rhertogh)
- Enh #7622: Allow `yii\data\ArrayDataProvider` to control the sort flags for `sortModels` through `yii\data\Sort::sortFlags` property (askobara)
- Bug #17863: `\yii\helpers\BaseInflector::slug()` doesn't work with an empty string as a replacement argument (haruatari)
- Bug #17875: Revert `move_uploaded_file()` function instead of `copy()` and `unlink()` for saving uploaded files when POST request (sup-ham)
2.0.32 January 21, 2020
-----------------------

View File

@ -178,10 +178,14 @@ class UploadedFile extends BaseObject
if ($this->hasError) {
return false;
}
if (false === $this->copyTempFile(Yii::getAlias($file))) {
return false;
$targetFile = Yii::getAlias($file);
if (is_resource($this->_tempResource)) {
$result = $this->copyTempFile($targetFile);
return $deleteTempFile ? @fclose($this->_tempResource) : (bool) $result;
}
return !$deleteTempFile || $this->deleteTempFile();
return $deleteTempFile ? move_uploaded_file($this->tempName, $targetFile) : copy($this->tempName, $targetFile);
}
/**
@ -193,9 +197,6 @@ class UploadedFile extends BaseObject
*/
protected function copyTempFile($targetFile)
{
if (!is_resource($this->_tempResource)) {
return $this->isUploadedFile($this->tempName) && copy($this->tempName, $targetFile);
}
$target = fopen($targetFile, 'wb');
if ($target === false) {
return false;
@ -207,32 +208,6 @@ class UploadedFile extends BaseObject
return $result;
}
/**
* Delete temporary file
*
* @return bool if file was deleted
* @since 2.0.32
*/
protected function deleteTempFile()
{
if (is_resource($this->_tempResource)) {
return @fclose($this->_tempResource);
}
return $this->isUploadedFile($this->tempName) && @unlink($this->tempName);
}
/**
* Check if file is uploaded file
*
* @param string $file path to the file to check
* @return bool
* @since 2.0.32
*/
protected function isUploadedFile($file)
{
return is_uploaded_file($file);
}
/**
* @return string original file base name
*/