Keyword

How is item image MD5 hash generated?

  • esedic
  • esedic's Avatar Topic Author
  • Offline
  • Senior Member
More
14 years 4 months ago #83488 by esedic
Hi!I'm trying to import large number of items (cca.5000) with K2 import tool but I'm stuck with images, since file names of the images are generated through MD5 hash.So my question is: is the file name generated randomly or is there a certain key I could follow? I tried to encrypt image file name through online md5 encryption service but file name is totally different.I can't imagine I would have to upload all the images manually.Thanks for helping me.

Please Log in or Create an account to join the conversation.

  • esedic
  • esedic's Avatar Topic Author
  • Offline
  • Senior Member
More
14 years 4 months ago #83489 by esedic
Replied by esedic on topic How is item image MD5 hash generated?
I'm still looking for a explanation how to generate MD5 hash from image filename, so I could batch import images in one step.

Gosh, I love K2 & its community so much, but sometimes it's really hard to get answers here :(

Please Log in or Create an account to join the conversation.

More
14 years 4 months ago #83490 by william white
Replied by william white on topic How is item image MD5 hash generated?
[root@ip-97-74-85-96 com_k2]# find . | xargs grep md5
will find many references to md5 in the file ./models/item.php
Just guessing that the code may be in that file that does the work

Please Log in or Create an account to join the conversation.

  • esedic
  • esedic's Avatar Topic Author
  • Offline
  • Senior Member
More
14 years 4 months ago #83491 by esedic
Replied by esedic on topic How is item image MD5 hash generated?
I've seen that file containing references to md5 hash, but I think it's in the backend where actually md5 hash gets generated (I'm not sure though). I was looking at file administrator/../com_k2/lib/class.upload.php where the image processing takes place. I hope hash generates only from file name and that there is no random integer generation.

But I was thinking that even if I found out how md5 hash generates, I would still have to rename images manually, which is the same as uploading one image at a time.

The best thing would be bulk importing, I'm thinking about hiring a programmer, I will see if there is enough money in my pocket after I pay my bills :)

Please Log in or Create an account to join the conversation.

More
14 years 4 months ago #83492 by Alex Webster
Replied by Alex Webster on topic How is item image MD5 hash generated?
After investigating how the item image name is generated I found this in administrator/components/com_k2/views/item/view.html.php:

if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_L.jpg'))
$item->image = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_L.jpg';

This means that the hash is generated from the word "Image" (with capital I), followed by the item ID. For example if we have a content item id 72 the hash is taken from "Image72" its generated using md5('Image72') (returns d6086de322f98f66cc694f32ea284557), so the filename will be d6086de322f98f66cc694f32ea284557.jpg.

Hope this will help somebody who is looking for the same thing as me in the future.

Please Log in or Create an account to join the conversation.

  • esedic
  • esedic's Avatar Topic Author
  • Offline
  • Senior Member
More
14 years 4 months ago #83493 by esedic
Replied by esedic on topic How is item image MD5 hash generated?
Thanks for this information, it's really useful, with the help of the Excel macros and PHP file rename script I will manage to solve my problem.

Please Log in or Create an account to join the conversation.

More
11 years 10 months ago #83494 by Steeve Cordier
Replied by Steeve Cordier on topic Re: How is item image MD5 hash generated?
Thx you very much for that :)

Please Log in or Create an account to join the conversation.

More
11 years 6 months ago #83495 by CMSGuy
Replied by CMSGuy on topic Re: How is item image MD5 hash generated?
As a follow-up on this topic, and in case K2 developers are listening, the existing K2 method of hashing item numbers to arrive at image file names is completely insecure. Because the hash being used is KNOWN to everyone (i.e. "Image"), in effect all instances of the hashing code only serve to make the image names longer.

Whereas with no effort the k2 item #1 image could be secured insecurely as simply:

/media/cache/image1.jpg

the addition of a non-secret hash results in the image being stored insecurely as simply:

/media/cache/THE_KNOWN_HASH_OF_IMAGE1.jpg

K2 needs to allow the administrator to store a secret hash string in the database and use that string as part of the hash code whenever image files are uploaded and retrieved. Until this feature is implemented every K2 item's images are completely insecure.

In the meantime, as a stop-gap measure, I might suggest that users use a plaintext editor like BBEdit to FIND AND REPLACE all instances of the string: .md5("Image" with your own new hash string such as .md5("12345"

This is pretty ridiculous.

Please Log in or Create an account to join the conversation.

More
10 years 7 months ago #83496 by Ignat
Replied by Ignat on topic Re: How is item image MD5 hash generated?
Hello! Anybody know, program, or method group renaiming files(images) in folder to md5 hash, for upload in k2 folder?
Sorry, if my English bad)

Please Log in or Create an account to join the conversation.

More
10 years 7 months ago #83497 by Lefteris
Replied by Lefteris on topic Re: How is item image MD5 hash generated?
@Ignat

You cannot do this. Even if you compute the hash correctly you will have only one image, while K2 uses 6 different image sizes per item.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum