Keyword

Where K2 store articles images in database?

More
13 years 3 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
13 years 3 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
13 years 3 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
13 years 2 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
13 years 2 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
13 years 2 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
13 years 2 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
12 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
12 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
12 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