xdan / jodit-connector-application

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rename if file exist on upload

coolibry opened this issue · comments

Hello,

i enable allowReplaceSourceFile to true,
then i can save picture when crop or resize,
but on upload, if file exist,
new file replace old file,

the perfect solution is to have UI to rename new file before upload,

from now i add unique id to file,
file components/BaseApplication.php line 333 :

					$new_path = $path . Helper::makeSafe($files['name'][$i]);
 //add unique id start of file name
					if (file_exists($new_path) && is_file ($new_path)){
						$new_path = $path .uniqid().'_'. Helper::makeSafe($files['name'][$i]);
					}

Thanks for for this software :).

Hello,
in addition when image editing i add the same tricks:
file components/BaseApplication.php line 225 :

			if (file_exists($path . $newName)) {
				if (!$this->config->allowReplaceSourceFile){
					throw new Exception(
						'File ' . $newName . ' already exists',
						Consts::ERROR_CODE_BAD_REQUEST
					);
				}
				else{ //add unique id start of file name
					$newName = uniqid().'_'. $newName;
				}
			}