Importing WordPress Attachments Into Custom Directories In wp-content/uploads/

Yes you can by programatically adding the attachment.

$upl = wp_upload_dir();
$target = $upl['basedir'] . '/YOUR_CUSTOM_FOLDERS/YOUR_FILE';
$filetype = wp_check_filetype($target);

$attachment = array(
    'post_mime_type' => $filetype['type'],
    'post_title' =>  $YOUR_FILE_TITLE,
    'post_content' => '',
    'post_status' => 'inherit'
);

wp_insert_attachment( $attachment, $target, $POST_ID_TO_ATTACH_TO );

This will tell WordPress that there is an attachment at $target and you can optionally attach it to a post with the last parameter in the call to wp_insert_attachment.

Leave a Comment