WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Can you expand on why you need to do this? – mrwweb Apr 27 '12 at 18:17
@mrwweb Sure, is that clear? I hope that's helpful. :) – goodseller Apr 27 '12 at 18:30

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.

share|improve this answer
@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 May 8 '12 at 19:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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