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?

  • 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.

| 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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