- Posts: 4
COMMUNITY FORUM
Where K2 store articles images in database?
- Enrico Fiorani
-
Topic Author
- Offline
- New Member
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
-
Topic Author
- Offline
- New Member
- Posts: 4
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
-
Topic Author
- Offline
- New Member
- Posts: 4
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.
- Alan Sparkes
-
- Offline
- Premium Member
- Posts: 118
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
-
Topic Author
- Offline
- New Member
- Posts: 4
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.
- Ben Chesters
-
- Offline
- New Member
- Posts: 16
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.
- william white
-
- Offline
- Platinum Member
- Posts: 3722
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.
- Ben Chesters
-
- Offline
- New Member
- Posts: 16
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.
- william white
-
- Offline
- Platinum Member
- Posts: 3722
not in the table
Please Log in or Create an account to join the conversation.
- Ben Chesters
-
- Offline
- New Member
- Posts: 16
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.
- Ben Chesters
-
- Offline
- New Member
- Posts: 16
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.
- william white
-
- Offline
- Platinum Member
- Posts: 3722
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.
- Ben Chesters
-
- Offline
- New Member
- Posts: 16
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.
- Markus Amanto
-
- Offline
- New Member
- Posts: 7
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.
- Markus Amanto
-
- Offline
- New Member
- Posts: 7
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.
- Hover
-
- Offline
- New Member
- Posts: 2
Please Log in or Create an account to join the conversation.
- Markus Amanto
-
- Offline
- New Member
- Posts: 7
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.
- Milan Stajkovic
-
- Offline
- New Member
- Posts: 5
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.
- Milan Stajkovic
-
- Offline
- New Member
- Posts: 5
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.
- B_Dark
-
- Offline
- Premium Member
- Posts: 126
Please Log in or Create an account to join the conversation.