+
+ /**
+ * 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.
+ */
+ public function uploadFile():array
+ {
+ switch (true) {
+ case $this->Connector->CONFIG['RATE_LIMIT']:
+ if (
+ $this->Connector->checkRateLimit(
+ $this->fingerPrintInfo,
+ $this->Connector->CONFIG['RATE_LIMIT_TIMEOUT'],
+ $this->Connector->CONFIG['RATE_LIMIT_FILES'],
+ )
+ ) {
+ $this->Connector->response->error(
+ 500,
+ 'Rate limit, please wait ' . $this->Connector->CONFIG['RATE_LIMIT_TIMEOUT'] .
+ ' seconds before uploading again.',
+ );
+ }
+ // Continue
+ case $this->Connector->CONFIG['BLACKLIST_DB']:
+ $this->Connector->checkFileBlacklist($this->FILE_INFO['SHA1']);
+ // Continue
+ case $this->Connector->CONFIG['FILTER_MODE'] && empty($this->FILE_INFO['EXTENSION']):
+ $this->checkMimeBlacklist();
+ // Continue
+ case $this->Connector->CONFIG['FILTER_MODE'] && !empty($this->FILE_INFO['EXTENSION']):
+ $this->checkMimeBlacklist();
+ $this->checkExtensionBlacklist();
+ // Continue
+ }
+ // If its not a dupe then skip checking if file can be written and
+ // skip inserting it into the DB.
+ if (!$this->FILE_INFO['DUPE']) {
+ if (!is_dir($this->Connector->CONFIG['FILES_ROOT'])) {
+ $this->Connector->response->error(500, 'File storage path not accessible.');
+ }
+ if (
+ !move_uploaded_file(
+ $this->FILE_INFO['TEMP_NAME'],
+ $this->Connector->CONFIG['FILES_ROOT'] .
+ $this->FILE_INFO['FILENAME'],
+ )
+ ) {
+ $this->Connector->response->error(500, 'Failed to move file to destination.');
+ }
+ if (!chmod($this->Connector->CONFIG['FILES_ROOT'] . $this->FILE_INFO['FILENAME'], 0644)) {
+ $this->Connector->response->error(500, 'Failed to change file permissions.');
+ }
+ $this->Connector->newIntoDB($this->FILE_INFO, $this->fingerPrintInfo);
+ }
+ return [
+ 'hash' => $this->FILE_INFO['SHA1'],
+ 'name' => $this->FILE_INFO['NAME'],
+ 'filename' => $this->FILE_INFO['FILENAME'],
+ 'url' => 'https://' . $this->Connector->CONFIG['FILE_DOMAIN'] . '/' . $this->FILE_INFO['FILENAME'],
+ 'size' => $this->FILE_INFO['SIZE'],
+ 'dupe' => $this->FILE_INFO['DUPE'],
+ ];