How to upload and add image to WP gallery programmatically?

I need to upload image to WP gallery from server side. So PHP script (in cron) must do the job without my interaction. So I wonder if WP has built in feature for this or should I upload image with CURL to server first and then use some WP functions to add image to post and associate it with post ?

Related posts

Leave a Reply

1 comment

  1. WordPress v3.5 now has some great drag and drop functionality for doing bulk image uploads. Your post seems to imply an automated process where a human wont be involved.

    There are 2 articles that have been written since your question was asked. Both provide slightly different solutions to your issue. I hope these help someone:

    Programmatically importing thousands of featured image post thumbnails into WordPress
    http://www.zdnet.com/blog/diy-it/programmatically-importing-thousands-of-featured-image-post-thumbnails-into-wordpress/118

    How To: Upload Media via URL Programmatically in WordPress
    http://theme.fm/2011/10/how-to-upload-media-via-url-programmatically-in-wordpress-2657/