From cd437ca036b6358015704923c7fbb0d6506329e8 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Tue, 6 May 2014 19:39:26 +0200 Subject: [PATCH] Fixed move_uploaded_file bullshit --- src/Api/ApiFileInput.php | 19 ++++++++++++++++--- src/Controllers/PostController.php | 6 ------ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/Api/ApiFileInput.php b/src/Api/ApiFileInput.php index e2fe7fd0..d7059d86 100644 --- a/src/Api/ApiFileInput.php +++ b/src/Api/ApiFileInput.php @@ -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); + } } diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index 12dc954a..34d4f07a 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -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);