1

I want to add an image to a K2 article using PHP. Is there a way to add an image when I am creating the article using PHP? Adding the title, body, and category is simple enough. All you have to do is enter the data into the database. There does not seem to be any table to store information to where the picture goes. At least I could not find anything in the tables #__k2_attachments , #__k2_items, or #__k2_extra_fields.

I read that images are stored as an "md(5) of the item id". Do I upload the image to the k2 cache directory with md5 encoding? I am guessing something like this.

$fileTemp = $file['tmp_name'];

$uploadPath_tb = JPATH_BASE."/media/k2/items/cache/".md5("image" . $id_num)."_S.jpg";

JFile::upload($fileTemp,$image);

However, when I try to do it, I get an error.

Warning: Failed to move file

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.