Keyword

Where K2 store articles images in database?

  • Enrico Fiorani
  • Enrico Fiorani's Avatar Topic Author
  • Offline
  • New Member
More
14 years 6 months ago #90470 by Enrico Fiorani
Where K2 store articles images in database? was created by Enrico Fiorani
Hi all, I'm new here.A little question: where K2 store articles images in database? 
I've search a lot in the tables with no lucky.

I know that the images are stored in media folder, but how about data?

Thank you very much!

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

  • Enrico Fiorani
  • Enrico Fiorani's Avatar Topic Author
  • Offline
  • New Member
More
14 years 6 months ago #90471 by Enrico Fiorani
Replied by Enrico Fiorani on topic Where K2 store articles images in database?
Ok, I've found a post that talk about stores the images as a "mld(5) of the item id". What that mean please?
There's a way to upload articles images via FTP and change the file name according to K2 system?
Obviously I rename all the file before upload, but how I've to rename all the files?

Help please!

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

  • Enrico Fiorani
  • Enrico Fiorani's Avatar Topic Author
  • Offline
  • New Member
More
14 years 6 months ago #90472 by Enrico Fiorani
Replied by Enrico Fiorani on topic Where K2 store articles images in database?
Again me :)
Sorry but I've found a solution.
My goal was upload all the images via csv/excel.
I've edited a couple of files and remove all the md5 (LOL not mdl(5) as reported in the post I've found!) calls in the source code both in admin part and front end part of K2 and now I can upload the images using the articles id as image name (plus the size suffix for the images).

A question: why using an md5 encr. for image name?
Thank you and sorry for the garbage of posts.
Admin can close discussion.

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

More
14 years 5 months ago #90473 by Alan Sparkes
Replied by Alan Sparkes on topic Where K2 store articles images in database?
This is puzzling - where is the link between the itemid and the image?
Are you saying that it is done dynamically ?

eg the image filename 'fc34f61d23b74be53ee07d469bd32064_M.jpg' is a hash with the item id in it?

This sounds an odd approach - especialy given SEO image potential or human readable needs on pics.

Dev team comment?

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

  • Enrico Fiorani
  • Enrico Fiorani's Avatar Topic Author
  • Offline
  • New Member
More
14 years 5 months ago #90474 by Enrico Fiorani
Replied by Enrico Fiorani on topic Where K2 store articles images in database?
Alan Sparkes said:This is puzzling - where is the link between the itemid and the image? Are you saying that it is done dynamically ?

eg the image filename 'fc34f61d23b74be53ee07d469bd32064_M.jpg' is a hash with the item id in it?

This sounds an odd approach - especialy given SEO image potential or human readable needs on pics.

Dev team comment?


Hi Alan, I can almost say yes at all your questions :)
I'll wait for a final Dev Team replay about this and yes "This sounds an odd approach" :)

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

More
14 years 4 months ago #90475 by Ben Chesters
Replied by Ben Chesters on topic Where K2 store articles images in database?
Hi, does anyone have an answer to this, I cannot see a trace of any of my images in the sql database?! Where are they!

Alan Sparkes said:
This is puzzling - where is the link between the itemid and the image? Are you saying that it is done dynamically ?

eg the image filename 'fc34f61d23b74be53ee07d469bd32064_M.jpg' is a hash with the item id in it?

This sounds an odd approach - especialy given SEO image potential or human readable needs on pics.

Dev team comment?

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

More
14 years 4 months ago #90476 by william white
Replied by william white on topic Where K2 store articles images in database?
see this post
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.

More
14 years 4 months ago #90477 by Ben Chesters
Replied by Ben Chesters on topic Where K2 store articles images in database?
Hi, which table does this informtion reside in within mysql? Thanks for your help!

William White said:
see this postAfter 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.

More
14 years 4 months ago #90478 by william white
Replied by william white on topic Where K2 store articles images in database?
"This means that the hash is generated from the word "Image" (with capital I), followed by the item ID"

not in the table

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

More
14 years 4 months ago #90479 by Ben Chesters
Replied by Ben Chesters on topic Where K2 store articles images in database?
I see, it is just that I am trying to import 300 pages to a site and need to place the file paths into the database, sounds like this is not going to be possible. :( Unless anyone knows of a way to do this? Thanks for your help as well, appreciate it.

William White said:
"This means that the hash is generated from the word "Image" (with capital I), followed by the item ID"

not in the table

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

More
14 years 4 months ago #90480 by Ben Chesters
Replied by Ben Chesters on topic Where K2 store articles images in database?
I see this encrypton thing now, is there anyway to avoid this happening? Also, I still cannot find where this is referenced in the database, where is this information stored? Even if I convert my 300 images to this coding, I still don't know how I will attach these to my items.!

Ben Chesters said:
I see, it is just that I am trying to import 300 pages to a site and need to place the file paths into the database, sounds like this is not going to be possible. :( Unless anyone knows of a way to do this? Thanks for your help as well, appreciate it.
William White said:
"This means that the hash is generated from the word "Image" (with capital I), followed by the item ID"

not in the table

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

More
14 years 4 months ago #90481 by william white
Replied by william white on topic Where K2 store articles images in database?
I havent researched it thorougly, but i think:

if a file is named Image105 (ofcourse with md5 hashing) and is stored in the proper directory...

When k2 tries to load an item image it tells it  to just go out and get md5(item105) and see it.

One thing i failed to mention is that there are multiple copies of the k2 item images in all different sizes so you can change the size that displays, and also, that the source files are also stored.

Probably best to either get someone to write a custom program for you or use the K2 item screen to add the images.

You might find an import routine that will handle the images - search for k2import here

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

More
14 years 4 months ago #90482 by Ben Chesters
Replied by Ben Chesters on topic Where K2 store articles images in database?
Hi, thanks. I have had a look a this and understand it a little better now. I would want to strip any encrytion off these file names due to SEO purposes, I wonder if it's possible to 'not' apply formatting.. But then it looks like this is connected to the Ajax stuff; when you click on the image and a light box pops up... If the images retained their own file names there'd be no way to 'tell' them which article to attach them to in this case. Would love to do it like that then have them written into the mysql, as images normally seem to be! One way round this is to add them to the fulltext editor box, but then this removes them from the php and all the plugins etc.. Seems I can't win! :)

William White said:
I havent researched it thorougly, but i think:

if a file is named Image105 (ofcourse with md5 hashing) and is stored in the proper directory...

When k2 tries to load an item image it tells it  to just go out and get md5(item105) and see it.

One thing i failed to mention is that there are multiple copies of the k2 item images in all different sizes so you can change the size that displays, and also, that the source files are also stored.

Probably best to either get someone to write a custom program for you or use the K2 item screen to add the images.

You might find an import routine that will handle the images - search for k2import here

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

More
14 years 3 months ago #90483 by Markus Amanto
Replied by Markus Amanto on topic Where K2 store articles images in database?
Hi all, 

First the disclaimer, I do not consider myself a professional programmer in any sense, more the stubborn trial-and-error kind of guy. Anyhow, this filename thing was really bugging me, mainly for SEO purposes. 

So I dug around some in the code. I usually try to avoid hacks as they can cause trouble at upgrades, but if you want to try the below it did what I wanted it to do for me. As usual, make back-ups of the files below before starting in case you mess up and need to revert.

So, enough with the disclaimers, here it goes (my K2 version by the way 2.4.1).

The basis for the whole thing is that I do not use the field Image Credits (found in K2 Item Editor -> Image) for anything, so decided to use that for file naming purposes. Also I do not have the lightbox function activated so I have not tested if that works with this hack.

1. in administrator/components/com_k2/models/item.php

Line 207, change to:

$handle->file_new_name_body = $row->image_credits;

2. components/com_k2/models/item.php

Starting on line 110, add the line:

$myfilename = $item->image_credits;

Then there are the following 16 lines below that which need to be modified to:

if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.$myfilename.'_XS.jpg')) $item->imageXSmall = JURI::root().'media/k2/items/cache/'.$myfilename.'_XS.jpg'; if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.$myfilename.'_S.jpg')) $item->imageSmall = JURI::root().'media/k2/items/cache/'.$myfilename.'_S.jpg'; if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.$myfilename.'_M.jpg')) $item->imageMedium = JURI::root().'media/k2/items/cache/'.$myfilename.'_M.jpg'; if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.$myfilename.'_L.jpg')) $item->imageLarge = JURI::root().'media/k2/items/cache/'.$myfilename.'_L.jpg'; if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.$myfilename.'_XL.jpg')) $item->imageXLarge = JURI::root().'media/k2/items/cache/'.$myfilename.'_XL.jpg'; if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.$myfilename.'_Generic.jpg')) $item->imageGeneric = JURI::root().'media/k2/items/cache/'.$myfilename.'_Generic.jpg'; 

3. When uploading a new file in the K2 Editor under Items -> Image in the backend, just make sure to put your filename in the "Item image credits" field (without any .jpg), for example: my_pretty_seo_image

Note: When I started this work I had not yet uploaded any images, so during testing I went in via FTP and erased all image files under media/k2/items/cache/, so I do not know how it works with overwriting existing images.

Now I am a bit mentally exhausted and in need of lunch so I might have forgotten some modification I made, but I hope the above is of some help to you.

/Markus

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

More
14 years 3 months ago #90484 by Markus Amanto
Replied by Markus Amanto on topic Where K2 store articles images in database?
One additional thing I noticed in the process. Joomla/K2 replaces some characters in the filename when uploading/saving the image which messed it up a bit for me at first, but in case that happens to you, you can use an ftp program to check the image folder and see what name your files have been given and then just make sure that what you have entered in the "Item image credits" matches that.

For example in my case it replaces my dashes that I first entered in the filename with underscores.

 

 

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

More
14 years 3 months ago #90485 by Hover
The same question, Where is stored the image name in the tables of mysql

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

More
14 years 3 months ago #90486 by Markus Amanto
Replied by Markus Amanto on topic Where K2 store articles images in database?
Image name is not stored in the database.
In the original setup when you upload an image it is saved with a filename that includes the id of the K2 item/article that it belongs to. Therefore no data is stored in database, when image is needed on the website, the code just looks for the image with the filename that contains the item/article id.
The actual filenames of images look a bit odd because they are hashed, or encoded, by K2 when you upload them. For example image37.jpg can become something like 23438aesd2348swrtujh2341184.jpg. But K2 can still read the actual id (37 in this example) from that hashed/coded filename.
Hope this answered your question.
Again, I am a K2 newbie, but this is how I have understood it to work.
M

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

More
13 years 11 months ago #90487 by Milan Stajkovic
Replied by Milan Stajkovic on topic Where K2 store articles images in database?
Doesnt work for me... I did exactly what u said, all my images are gone now. I'll try to find a problem. By the way, i'm testing it on my local xampp server, does it makes any changes?
Markus Amanto said:
One additional thing I noticed in the process. Joomla/K2 replaces some characters in the filename when uploading/saving the image which messed it up a bit for me at first, but in case that happens to you, you can use an ftp program to check the image folder and see what name your files have been given and then just make sure that what you have entered in the "Item image credits" matches that.

For example in my case it replaces my dashes that I first entered in the filename with underscores.

 

 

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

More
13 years 11 months ago #90488 by Milan Stajkovic
Replied by Milan Stajkovic on topic Where K2 store articles images in database?
"
1. in administrator/components/com_k2/models/item.php

Line 207, change to:

$handle->file_new_name_body = $row->image_credits;

"is on line 198 in my code, and it does the job when i modify it.But, when i upload a photo in my backend it only works when i put "_" betwin image name in my "Item image credits" field. The problem is that it shows the image in my front-end, renamed as we wanted it, but there is no thumbnail image in back-end item image tab, and it is not indicating that the article has image at all...If u ask me i dont care about back-end,  as long as the trick does the SEO job... Milan Stajkovic said:

Doesnt work for me... I did exactly what u said, all my images are gone now. I'll try to find a problem. By the way, i'm testing it on my local xampp server, does it makes any changes? Markus Amanto said:
One additional thing I noticed in the process. Joomla/K2 replaces some characters in the filename when uploading/saving the image which messed it up a bit for me at first, but in case that happens to you, you can use an ftp program to check the image folder and see what name your files have been given and then just make sure that what you have entered in the "Item image credits" matches that.

For example in my case it replaces my dashes that I first entered in the filename with underscores.

 

 

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

More
13 years 11 months ago #90489 by B_Dark
Replied by B_Dark on topic Where K2 store articles images in database?
Did you find any solution?

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


Powered by Kunena Forum