Unable to upload files withe same name twice?
-
- Phoca Newbie
- Posts: 2
- Joined: 01 Feb 2013, 18:31
Unable to upload files withe same name twice?
Hi All,
I have installed phoca gallery on Joomla.
When I try to upload an image with the same file name as the one that was uploaded earlier, I get an error saying file already exists.
But I need the users to be able to upload files with the same name multiple times without getting over written or giving error.
How do we upload files with the same filename multiple times?
Thank you.
I have installed phoca gallery on Joomla.
When I try to upload an image with the same file name as the one that was uploaded earlier, I get an error saying file already exists.
But I need the users to be able to upload files with the same name multiple times without getting over written or giving error.
How do we upload files with the same filename multiple times?
Thank you.
Tags:
- Jan
- Phoca Hero
- Posts: 48403
- Joined: 10 Nov 2007, 18:23
- Location: Czech Republic
- Contact:
Re: Unable to upload files withe same name twice?
Hi, for such feature you need to customize the component (the upload part and remove the protection for overwriting files) There is no option as default to overwrite images
Jan
Jan
If you find Phoca extensions useful, please support the project
-
- Phoca Newbie
- Posts: 2
- Joined: 01 Feb 2013, 18:31
Re: Unable to upload files withe same name twice?
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:
In realsingleUpload() function, line 379 to 387,
Replace:
With:
Replace:
With:
This works and renames any duplicate filename with _1, _2 and on.
Thank you.
Avi
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;
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;
}
}
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'];
}
Code: Select all
if ((int)$frontEnd > 0) {
return $this->file_Name;
}
Thank you.
Avi
- Jan
- Phoca Hero
- Posts: 48403
- Joined: 10 Nov 2007, 18:23
- Location: Czech Republic
- Contact:
Re: Unable to upload files withe same name twice?
Hi, thank you for the guide.
Jan
Jan
If you find Phoca extensions useful, please support the project
-
- Phoca Newbie
- Posts: 2
- Joined: 22 Apr 2013, 17:07
Re: Unable to upload files withe same name twice?
Your solution works very well and thank you very much but if I use multiple upload doesn't work.
Any Idea?
Any Idea?
-
- Phoca Newbie
- Posts: 3
- Joined: 13 Apr 2012, 19:26
Re: Unable to upload files withe same name twice?
Is there and update or can anybody help me with an updated version of this code edit for the 4.1.0 version of Phoca Gallery.
Or if there is another way of doing this that I have missed.
Thanks in advance.
Or if there is another way of doing this that I have missed.
Thanks in advance.
- Jan
- Phoca Hero
- Posts: 48403
- Joined: 10 Nov 2007, 18:23
- Location: Czech Republic
- Contact:
Re: Unable to upload files withe same name twice?
Hi, for now I think, there is no update of this guide, unfortunately I am not able to somehow update this guide as I have no experiences with hardware which has such limitation - so really cannot give any clue advice
Jan
Jan
If you find Phoca extensions useful, please support the project
-
- Phoca Newbie
- Posts: 2
- Joined: 22 Jun 2014, 04:31
Re: Unable to upload files withe same name twice?
have you found other way to upload from _ _/_ _ devices?
I tryed this method to replace in php but doesnt work, maybe has been updated fileuploaded.php at the last version of phoca gallery...
anyway, Great component
Thanks
I tryed this method to replace in php but doesnt work, maybe has been updated fileuploaded.php at the last version of phoca gallery...
anyway, Great component
Thanks
-
- Phoca Newbie
- Posts: 4
- Joined: 12 Apr 2015, 01:16
Re: Unable to upload files withe same name twice?
This method now returns error:
Fatal error: Using $this when not in object context
Can anyone fix this?
Terry
Fatal error: Using $this when not in object context
Can anyone fix this?
Terry
- Jan
- Phoca Hero
- Posts: 48403
- Joined: 10 Nov 2007, 18:23
- Location: Czech Republic
- Contact:
Re: Unable to upload files withe same name twice?
Hi, you get some javascript error, so see the error console to know exactly from which part the error is comming (which file, which line, etc.)
https://www.phoca.cz/documents/16-joomla ... -conflicts
Jan
https://www.phoca.cz/documents/16-joomla ... -conflicts
Jan
If you find Phoca extensions useful, please support the project