Post by eBsimplicity » Thu Jun 20, 2013 9:23 pm

Hello,

In the current version of the image manager, images with the same file names overwrites each other when uploaded.

What I need is a simple tweak so that if there is a duplicate image name, the new image name will simply, i.e., rename itself with an additional letter or number.

I tried searching for this, but couldn't find anything to my surprise.

Any ideas?

Thanks!

User avatar
New member

Posts

Joined
Thu Dec 08, 2011 12:21 am

Post by eBsimplicity » Thu Jun 20, 2013 11:30 pm

10 bucks to any reputable who can fix this for me. I can't imagine it'd be too hard. PM for pw/user etc. Thank you.

User avatar
New member

Posts

Joined
Thu Dec 08, 2011 12:21 am

Post by hory123 » Mon Nov 13, 2017 6:10 pm

Have you find any solution for this ?

Newbie

Posts

Joined
Tue Jun 05, 2012 2:17 am

Post by DigitCart » Mon Nov 13, 2017 6:41 pm

OpenCart 2.3
Open this file:

Code: Select all

admin\controller\common\filemanager.php
Find:

Code: Select all

move_uploaded_file($file['tmp_name'], $directory . '/' . $filename);
Add before it:

Code: Select all

if(file_exists($directory . '/' . $filename)){
	$filename = $this->rename($directory, $filename);
}
Find:

Code: Select all

public function folder() {
Add before it:

Code: Select all

protected function rename($directory, $filename){
	$basename = pathinfo($filename, PATHINFO_FILENAME);
	$extension = pathinfo($filename, PATHINFO_EXTENSION);
	$i = 1;
	do{
		$newname = $basename . '_' . $i++ . '.' . $extension;
	} while(
		file_exists($directory . '/' . $newname)
	);
	return $newname;
}
This will check and rename new file if file exists:
image.png
image_1.png
image_2.png
image_3.png
..

My Extensions / DigitCart


User avatar
Active Member

Posts

Joined
Thu Jun 22, 2017 5:32 pm


Post by straightlight » Mon Nov 13, 2017 10:16 pm

The only downside with this add-on is whenever an upgrade is involved or site restoration and some or all of the images needs to compared, different filenames could bring harden tasks to the merchants in order to retrace those images.

The most generated errors being found on Opencart forum originates from contributed programming.

Regards,
Straightlight


Guru Member
Online

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by IP_CAM » Tue Nov 14, 2017 4:52 am

Well, since this is originally a 1.5.6.x Topic, one of those Extensions below could
solve such Problems for v.1.5.6.x Users. And the third Mod will fix white-space
related Link Problems. Just to have it mentioned ! ;)
Ernie
---
Web-safe Product Image Filenames free, OC v.1.5.6.1 - 1.5.6.5_rc:
This vQmod OpenCart module is used to sanitize uploaded image filenames so
they are web- and Facebook-safe. When you upload an image in the OpenCart
File Manager, this module will rename the file to be web-safe as follows:
1. trim the filename if it is more than 31 characters including the extension;
2. change any character other than a-z, A-Z, 0-9 into hyphen (-);
3. strip any leading and trailing hyphen of the filename.
https://www.opencart.com/index.php?rout ... n_id=21251
---
Mass Image Rename free, OC v.1.5.0 - 1.5.6.5_rc:
this will mass rename product images in a seo friendly format
currently supported are renaming images by name, sku, ean, jpn, upc, mpn and isbn.
Currently only default opencart tables are supported.
https://www.opencart.com/index.php?rout ... n_id=14343
---
Replace space to hyphen free, OC v.1.5.6.x:
Replace space to hyphen in image's name which is uploaded to website. Just test on opencart 1.5.6.1:
https://www.opencart.com/index.php?rout ... n_id=20635
---

Ernie's OpenCart v.1.5.6.5 LIGHT + OpenShop Admin v.1.75 Test Sites
http://www.bigmax.ch - http://www.evelo.li - http://www.openshop.li
Image


User avatar
Guru Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland
Who is online

Users browsing this forum: No registered users and 51 guests