Fixed move_uploaded_file bullshit

This commit is contained in:
Marcin Kurczewski 2014-05-06 19:39:26 +02:00
parent 42b8049ae5
commit cd437ca036
2 changed files with 16 additions and 9 deletions

View file

@ -6,12 +6,25 @@ class ApiFileInput
{
public $filePath;
public $fileName;
public $originalPath;
public function __construct($filePath, $fileName)
{
//todo: move_uploaded_file here
//concerns post thumbs and post content
$this->filePath = $filePath;
$tmpPath = tempnam(sys_get_temp_dir(), 'upload') . '.dat';
$this->originalPath = $tmpPath;
//php "security" bullshit
if (is_uploaded_file($filePath))
move_uploaded_file($filePath, $tmpPath);
else
copy($filePath, $tmpPath);
$this->filePath = $tmpPath;
$this->fileName = $fileName;
}
public function __destruct()
{
TransferHelper::remove($this->originalPath);
}
}

View file

@ -106,8 +106,6 @@ class PostController
$jobArgs[EditPostContentJob::POST_CONTENT] = new ApiFileInput(
$file['tmp_name'],
$file['name']);
TransferHelper::remove($file['tmp_name']);
}
Api::run(new AddPostJob(), $jobArgs);
@ -150,8 +148,6 @@ class PostController
$jobArgs[EditPostContentJob::POST_CONTENT] = new ApiFileInput(
$file['tmp_name'],
$file['name']);
TransferHelper::remove($file['tmp_name']);
}
if (!empty($_FILES['thumb']['name']))
@ -162,8 +158,6 @@ class PostController
$jobArgs[EditPostThumbJob::THUMB_CONTENT] = new ApiFileInput(
$file['tmp_name'],
$file['name']);
TransferHelper::remove($file['tmp_name']);
}
Api::run(new EditPostJob(), $jobArgs);