function get_unique_filename($file)
{
$filename = strtolower($file['name']);
$info = pathinfo($filename);
$ext = $info['extension'];
$name = basename($filename, ".{$ext}");
if ($name === ".{$ext}") {
$name = '';
}
$number = '';
if (empty($ext)) {
$ext = '';
} else {
$ext = strtolower(".{$ext}");
}
$filename = $this->_sanitize_filename($filename, $ext);
$check = $this->_check_uniqueness_with_backend($filename);
if (200 == $check['http_code']) {
$obj = json_decode($check['content']);
if (isset($obj->filename) && basename($obj->filename) != basename($post_url)) {
$file['name'] = $obj->filename;
}
} else {
if (406 == $check['http_code']) {
$file['error'] = __('The file type you uploaded is not supported.');
} else {
$file['error'] = sprintf(__('Error getting the file name from the remote servers: Code %d'), $check['http_code']);
}
}
return $file;
}