- 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);
+ 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