Skip to content

Commit

Permalink
scrutinizer
Browse files Browse the repository at this point in the history
  • Loading branch information
carono committed Feb 28, 2018
1 parent ad745b3 commit a994d3a
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions Uploader.php
Expand Up @@ -140,12 +140,50 @@ public function getUserId()
* @param $destination
* @throws \Exception
*/
public function copy($source, $destination)
protected function copyUploadedFile($source, $destination)
{
if (is_uploaded_file($source) && !move_uploaded_file($source, $destination)) {
if (!move_uploaded_file($source, $destination)) {
throw new \Exception('Unknown upload error');
} elseif ($this->delete ? !rename($source, $destination) : !copy($source, $destination)) {
throw new \Exception('Failed to write file to disk');
}
}

/**
* @param $source
* @param $destination
* @throws \Exception
*/
protected function renameFile($source, $destination)
{
if (!rename($source, $destination)) {
throw new \Exception('Failed rename file');
}
}

/**
* @param $source
* @param $destination
* @throws \Exception
*/
protected function copyFile($source, $destination)
{
if (!copy($source, $destination)) {
throw new \Exception('Failed copy file');
}
}

/**
* @param $source
* @param $destination
* @throws \Exception
*/
public function copy($source, $destination)
{
if (is_uploaded_file($source)) {
$this->copyUploadedFile($source, $destination);
} elseif ($this->delete) {
$this->renameFile($source, $destination);
} else {
$this->copyFile($source, $destination);
}
}

Expand Down

0 comments on commit a994d3a

Please sign in to comment.