Unable to upload files withe same name twice?

avi0007
Phoca Newbie
Phoca Newbie
Posts: 2
Joined: 01 Feb 2013, 18:31

Unable to upload files withe same name twice?

Postby avi0007 » 04 Feb 2013, 04:40

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.


User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 36670
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Unable to upload files withe same name twice?

Postby Jan » 07 Feb 2013, 23:49

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
If you find Phoca extensions useful, please support the project

avi0007
Phoca Newbie
Phoca Newbie
Posts: 2
Joined: 01 Feb 2013, 18:31

Re: Unable to upload files withe same name twice?

Postby avi0007 » 26 Feb 2013, 11:06

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

User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 36670
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Unable to upload files withe same name twice?

Postby Jan » 28 Feb 2013, 19:19

Hi, thank you for the guide.
Jan
If you find Phoca extensions useful, please support the project

Darkn3ss
Phoca Newbie
Phoca Newbie
Posts: 2
Joined: 22 Apr 2013, 17:07

Re: Unable to upload files withe same name twice?

Postby Darkn3ss » 03 Jul 2013, 17:40

Your solution works very well and thank you very much but if I use multiple upload doesn't work.
Any Idea?

mjrumble
Phoca Newbie
Phoca Newbie
Posts: 3
Joined: 13 Apr 2012, 19:26

Re: Unable to upload files withe same name twice?

Postby mjrumble » 25 Apr 2014, 16:46

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.

User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 36670
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Unable to upload files withe same name twice?

Postby Jan » 25 Apr 2014, 23:57

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 :-( :idea:

Jan
If you find Phoca extensions useful, please support the project

doctor88
Phoca Newbie
Phoca Newbie
Posts: 2
Joined: 22 Jun 2014, 04:31

Re: Unable to upload files withe same name twice?

Postby doctor88 » 17 Jul 2014, 07:06

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

touraku
Phoca Newbie
Phoca Newbie
Posts: 4
Joined: 12 Apr 2015, 01:16

Re: Unable to upload files withe same name twice?

Postby touraku » 17 Apr 2015, 13:33

This method now returns error:
Fatal error: Using $this when not in object context

Can anyone fix this?
Terry

User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 36670
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Unable to upload files withe same name twice?

Postby Jan » 19 Apr 2015, 00:05

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.)
http://www.phoca.cz/documents/16-joomla ... -conflicts
Jan
If you find Phoca extensions useful, please support the project


Return to “General Forum”

Who is online

Users browsing this forum: No registered users and 1 guest