Upload files to wp-content/uploads – What to add in DB?

Given that I upload a file to wp-content/uploads via FTP, what are the records that I should create in the DB in order for the MediaManager to recognize those new uploads?

Related posts

Leave a Reply

2 comments

  1. There is media_handle_sideload() function in core meant for processing files not uploaded through media interface.

    It’s not exactly what you need since it assumes file is outside of uploads and needs to be moved there as part of process, but it should give you and idea on generating and inserting it as valid attachment.

  2. … what are the records that I should create in the DB in order for
    the MediaManager to recognize those new uploads?

    Honestly, I don’t know what the minimum required data is but…

    1. WordPress stored the primary data in the $wpdb->posts table as an
      attachment post type.
    2. And significant meta data is stored in the $wpdb->postmeta table
      under at least two keys (that I can spot at a glance)–
      _wp_attached_file and _wp_attachment_metadata.

    I am sure you will have to populate at least the $wpdb->post table. You may be able to neglect some of the post meta, but I don’t know for sure.

    At any rate, don’t try to construct the data yourself. Crawl the directory and use Core functions to do the work for your, or use a plugin that does it for you, such as this one. I can’t vouch for it but it seems to be close to what you need.