+
+ /**
+ * Takes a file, checks if it's blacklisted, moves it to the file storage, and then logs it to the database
+ *
+ * @return array An array containing the hash, name, url, and size of the file.
+ * @throws \Exception
+ */
+ public function uploadFile():array
+ {
+ if ($this->Connector->CONFIG['RATE_LIMIT']) {
+ $this->Connector->checkRateLimit($this->fingerPrintInfo);
+ }
+ if ($this->Connector->CONFIG['BLACKLIST_DB']) {
+ $this->Connector->checkFileBlacklist($this->FILE_INFO);
+ }
+ if ($this->Connector->CONFIG['FILTER_MODE'] && empty($this->FILE_INFO['EXTENSION'])) {
+ $this->checkMimeBlacklist();
+ }
+ if ($this->Connector->CONFIG['FILTER_MODE'] && !empty($this->FILE_INFO['EXTENSION'])) {
+ $this->checkMimeBlacklist();
+ $this->checkExtensionBlacklist();
+ }
+ if (!is_dir($this->Connector->CONFIG['FILES_ROOT'])) {
+ throw new Exception('File storage path not accessible.', 500);
+ }
+ if (
+ !move_uploaded_file(
+ $this->FILE_INFO['TEMP_NAME'],
+ $this->Connector->CONFIG['FILES_ROOT'] .
+ $this->FILE_INFO['NEW_NAME'],
+ )
+ ) {
+ throw new Exception('Failed to move file to destination', 500);
+ }
+ if (!chmod($this->Connector->CONFIG['FILES_ROOT'] . $this->FILE_INFO['NEW_NAME'], 0644)) {
+ throw new Exception('Failed to change file permissions', 500);
+ }
+ if (!$this->Connector->CONFIG['LOG_IP']) {
+ $this->fingerPrintInfo['ip'] = null;
+ }
+ $this->Connector->newIntoDB($this->FILE_INFO, $this->fingerPrintInfo);
+ return [
+ 'hash' => $this->FILE_INFO['SHA1'],
+ 'name' => $this->FILE_INFO['NAME'],
+ 'url' => $this->Connector->CONFIG['FILES_URL'] . '/' . $this->FILE_INFO['NEW_NAME'],
+ 'size' => $this->FILE_INFO['SIZE'],
+ ];