Created
September 13, 2017 12:30
-
-
Save lpj145/1406ea7e1581ee488af2d37e9b1b9b6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace FiremonPHP\Storage; | |
class FileStorage | |
{ | |
private $files = []; | |
public function __construct(array $files) | |
{ | |
$this->storeInternal($files); | |
} | |
/** | |
* @param $files | |
*/ | |
private function storeInternal($files) | |
{ | |
if ($this->isMultiplePostFiles($files)) { | |
$this->byMultiplePostFiles($files); | |
return; | |
} | |
} | |
private function byMultipleDataString(array $dataFiles) | |
{ | |
foreach ($dataFiles as $fileKey => $file) { | |
$fileName = $this->generateName(); | |
} | |
} | |
/** | |
* @param array $files | |
*/ | |
private function byMultiplePostFiles(array $files) | |
{ | |
$countFiles = count($files['name']); | |
for ($i = 0; $i < $countFiles; $i++) { | |
$fileName = $this->generateName(); | |
$this->files[$fileName]['data'] = fopen($files['tmp_name'][$i], 'r'); | |
$this->files[$fileName]['metadata']['name'] = $files['name'][$i]; | |
$this->files[$fileName]['metadata']['type'] = $files['type'][$i]; | |
} | |
} | |
/** | |
* @param array $file | |
* @return bool | |
*/ | |
private function isMultiplePostFiles(array $file) | |
{ | |
return isset($file['name']) && count($file['name']) > 0; | |
} | |
/** | |
* @return string | |
*/ | |
private function generateName() | |
{ | |
return md5(uniqid(rand(), true)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment