0

How to move an image in a plugin to the upload directory and make it as a media of wordpress?

I would like to use them in posts.

Expand question:

I would like to generate images using other programs and saved in the temporary folder of my plugin directory.

eg. plugin-name/tmp/image_01.jpg

Then, I would like to upload the image to the upload directory an use it as a media source.

Is that possible?

2
  • Can you expand on why you need to do this?
    – mrwweb
    Commented Apr 27, 2012 at 18:17
  • @mrwweb Sure, is that clear? I hope that's helpful. :)
    – goodseller
    Commented Apr 27, 2012 at 18:30

1 Answer 1

1

Check out wp_insert_attachment(). Takes an $attachment array of metadata and a $filename and inserts it into the media library. The Codex page has a good snippet so I won't include one here.

1
  • @goodseller if this answered your problem, make sure to accept it as the answer. Otherwise, update your question and explain why this didn't work.
    – mrwweb
    Commented May 8, 2012 at 19:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.