Skip to content
Permalink
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
daftspunk committed Mar 29, 2022
1 parent 95ce496 commit fe569f3
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Database/Attach/File.php
Expand Up @@ -124,14 +124,14 @@ public function fromPost($uploadedFile)
/**
* fromFile creates a file object from a file on the disk
*/
public function fromFile($filePath)
public function fromFile($filePath, $filename = null)
{
if ($filePath === null) {
return;
}

$file = new FileObj($filePath);
$this->file_name = $file->getFilename();
$this->file_name = empty($filename) ? $file->getFilename() : $filename;
$this->file_size = $file->getSize();
$this->content_type = $file->getMimeType();
$this->disk_name = $this->getDiskName();
Expand All @@ -152,10 +152,11 @@ public function fromData($data, $filename)
return;
}

$tempPath = temp_path(basename($filename));
$tempName = str_replace('.', '', uniqid('', true)) . '.tmp';
$tempPath = temp_path($tempName);
FileHelper::put($tempPath, $data);

$file = $this->fromFile($tempPath);
$file = $this->fromFile($tempPath, basename($filename));
FileHelper::delete($tempPath);

return $file;
Expand Down

0 comments on commit fe569f3

Please sign in to comment.