Anno 2018 this might work too (PHP 7.1):
class MyUploadHandler extends UploadHandler { public function __construct($options = array(), $initialize = true, $error_messages = null) { $options += array( 'overwrite_existing' => true ); parent::__construct($options, $initialize, $error_messages); } protected function get_unique_filename($file_path, $name, $size, $type, $error, $index, $content_range) { if ($this->options['overwrite_existing'] ?? false) { return $name; } return parent::get_unique_filename($file_path, $name, $size, $type, $error, $index, $content_range); } }
This avoids the need to modify the source code, which can then be used as a library.
source share