fileTmpPath = $file['tmp_name']; $this->fileName = $file['name']; $this->fileSize = $file['size']; $this->fileType = $file['type']; $this->fileNameCmps = explode('.', $this->fileName); $this->fileExtension = strtolower(end($this->fileNameCmps)); $this->allowedFileExtensions = $extensions; } // public function setNewFileName(): void // { // $this->newFileName = md5(time() . $this->fileName) . '.' . $this->fileExtension; // } // public function checkExtension(): bool // { // if (in_array($this->fileExtension, $this->allowedFileExtensions)) { // return true; // } // return false; // } public function upload() { $newFileName = md5(time() . $this->fileName) . '.' . $this->fileExtension; if (in_array($this->fileExtension, $this->allowedFileExtensions)) { mkdir('./resources/upload/' . mb_substr($newFileName, 0, 2) . '/' . mb_substr($newFileName, 2, 2) . '/', 0777, true); $uploadFileDir = './resources/upload/' . mb_substr($newFileName, 0, 2) . '/' . mb_substr($newFileName, 2, 2) . '/'; $dest_path = $uploadFileDir . $newFileName; move_uploaded_file($this->fileTmpPath, $dest_path); } else { return false; } } }