How to register images uploaded via FTP in media library?

It’s because you’re not registering them as a media type. Every upload is a WordPress post of the attachment type.

To start, it would be something like this:

$file_name="Some Name";
$file_path="/path/to/uploads/2012/08/04/newfile.jpg";
$file_url="http://url/to/uploads/2012/08/04/newfile.jpg";
$wp_filetype = wp_check_filetype($file, null);
$attachment = array(
    'guid'           => $file_url,
    'post_mime_type' => $wp_filetype['type'],
    'post_title'     => $file_name,
    'post_status'    => 'inherit',
    'post_date'      => date('Y-m-d H:i:s')
);
$attachment_id = wp_insert_attachment($attachment, $file_path);
$attachment_data = wp_generate_attachment_metadata($attachment_id, $file_path);
wp_update_attachment_metadata($attachment_id, $attachment_data);

That should create an entry in your Media panel, and also convert the image to all the sizes you’re using in your theme.

A good option for you is to insert the above procedure in your upload.php. For that, you would need to include the WordPress required files too. Otherwise you would have to tell WordPress to run this somehow, maybe by a $_REQUEST query or by a cron job.

Leave a Comment