Hi,
The above issue is solved now. I have customized the code to rename the file so that when people upload files with the same name it gets renamed when uploaded. For example, test.jpg when uploaded again will be renamed as test_1.jpg
For this you have to do the following:
In the file, /administrator/components/com_phocagallery/libraries/phocagallery/file/fileupload.php
Add after line 17:
- Code: Select all
private $file_Name;
In realsingleUpload() function, line 379 to 387,
Replace:
- Code: Select all
if (JFile::exists($filepath)) {
if ($return) {
$app->redirect(base64_decode($return).'&folder='.$folderUrl, JText::_('COM_PHOCAGALLERY_FILE_ALREADY_EXISTS'), 'error');
exit;
} else {
$app->redirect($componentUrl, JText::_('COM_PHOCAGALLERY_FILE_ALREADY_EXISTS'), 'error');
exit;
}
}
With:
- Code: Select all
if (JFile::exists($filepath)) {
// CHeck if there is another file version using the _ format
//CUSTOM CODE STARTS
$f = $file['name'];
$filename = explode(".",$f);
$filename = $filename[0];
$ext = explode(".",$f);
$ext = $ext[1];
for($m = 1; $m <= 100 ; $m++){
$this->file_Name = $filename."_".$m.".".$ext;
$filepath1 = JPath::clean($path->image_abs.$folder.strtolower($this->file_Name));
if(!JFile::exists($filepath1)){
$this->file_Name = $filename."_".($m).".".$ext;
$filepath1 = JPath::clean($path->image_abs.$folder.strtolower($this->file_Name));
break;
}
else{
$mcount = explode("_",$this->file_Name);
$mcount = $mcount[1];
if(!empty($mcount)){
$count1 = $mcount[1];
$count = explode(".",$count1);
$count = $count[0];
$m = $m+$count;
}else{
$count = 1;
$m = $m+$count;
}
}
}
$filepath = $filepath1;
}
else{
$this->file_Name = $file['name'];
}
Replace:
- Code: Select all
if ((int)$frontEnd > 0) {
return $file['name'];
}
With:
- Code: Select all
if ((int)$frontEnd > 0) {
return $this->file_Name;
}
This works and renames any duplicate filename with _1, _2 and on.
Thank you.
Avi