Actual Image File Names Instead of Garble

Questions around the TYPO3 integration and plugins
Forum rules
Always add your TYPO3, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
superscotty19
Posts: 95
Joined: 13 May 2019, 08:09

Actual Image File Names Instead of Garble

Post by superscotty19 » 07 May 2020, 20:57

Hi,

Looking to migrate from another e-comm to Aimeos. We have a LOT of products with corresponding photos. In the old e-commerce system, the product image file names were respected and easy to browse via filelist. However, Aimeos seems to rename every file we upload into some sub-directories with garbled file names. Can we just have all images in one directory, with actual file names?

Thanks,
-Scott.

User avatar
aimeos
Administrator
Posts: 7835
Joined: 01 Jan 1970, 00:00

Re: Actual Image File Names Instead of Garble

Post by aimeos » 09 May 2020, 09:24

You can use the original file names in the CSV when importing the products for example and they won't renamed. The generated preview images are renamed to a hash for security reasons and distributed evenly into up to 256 subdirectories for performance reasons. If you don't want that, you have to write your own media controller and replace that method:
https://github.com/aimeos/aimeos-core/b ... #L380-L402
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

superscotty19
Posts: 95
Joined: 13 May 2019, 08:09

Re: Actual Image File Names Instead of Garble

Post by superscotty19 » 14 May 2020, 23:59

k, WHOA,

Clearly you're 2 steps ahead of me. That's a really good answer! Now that I think of it, I guess there's no need to care about the filename since the product is stored in Aimeos ... I was just thinking, what if that's my only photo of a product and a potential client asks for a download of it - how would I get it? In that case and referencing the code you provided, am I reading correctly that all we need to do is modify $filename:

Code: Select all

$list = $this->context->getConfig()->get( 'controller/common/media/standard/extensions', [] );

$filename = md5( $filename . getmypid() . microtime( true ) );
$ext = isset( $list[$mimeext] ) ? '.' . $list[$mimeext] : ( ctype_alpha( $mimeext ) ? '.' . $mimeext : '' );

return "${type}/${filename[0]}/${filename[1]}/${filename}${ext}";
... to read:

Code: Select all

$list = $this->context->getConfig()->get( 'controller/common/media/standard/extensions', [] );

$filename = md5( $filename );
$ext = isset( $list[$mimeext] ) ? '.' . $list[$mimeext] : ( ctype_alpha( $mimeext ) ? '.' . $mimeext : '' );

return "${type}/${filename[0]}/${filename[1]}/${filename}${ext}";
?
Thanks as always,
-Scott.

User avatar
aimeos
Administrator
Posts: 7835
Joined: 01 Jan 1970, 00:00

Re: Actual Image File Names Instead of Garble

Post by aimeos » 15 May 2020, 11:32

This would still create a hashed file name. I would use something like this:

Code: Select all

$filename = trim( preg_replace( '/[^A-Za-z0-9]+/', '_', $filename ), '_' );
$filename = substr( md5( $filename . getmypid() . microtime( true ) ), -8 ) . '_' . $filename;
For '../../My file~.jpg.exe' this will create "a8c413f0_My_file_jpg_exe" which it's still safe and unique. We will use that also in the next Aimeos version.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply