- }
- 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);
- }
-
-
-
- $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'],
- ];
- }
-
- /**
- * Takes the amount of files that are being uploaded, and creates a fingerprint of the user's IP address,
- * user agent, and the amount of files being
- * uploaded
- *
- * @param $files_amount int The amount of files that are being uploaded.
- *
- * @throws \Exception
- */
- public function fingerPrint(int $files_amount): void
- {
- if (!empty($_SERVER['HTTP_USER_AGENT'])) {
- $USER_AGENT = filter_var($_SERVER['HTTP_USER_AGENT'], FILTER_SANITIZE_ENCODED);
- $this->fingerPrintInfo = [
- 'timestamp' => time(),
- 'useragent' => $USER_AGENT,
- 'ip' => $_SERVER['REMOTE_ADDR'],
- 'ip_hash' => hash('sha1', $_SERVER['REMOTE_ADDR'] . $USER_AGENT),
- 'files_amount' => $files_amount,
+ }
+ // 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'],