Extending WP’s upload/insert media functionality

Both of these are possible.

Insert Attachment into Media Library

By using the wp_insert_attachment function, you can insert your uploaded images to the Media Library.

This is the example code from the Docs:

<?php
  $wp_filetype = wp_check_filetype(basename($filename), null );
  $wp_upload_dir = wp_upload_dir();
  $attachment = array(
     'guid' => $wp_upload_dir['baseurl'] . _wp_relative_upload_path( $filename ), 
     'post_mime_type' => $wp_filetype['type'],
     'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
     'post_content' => '',
     'post_status' => 'inherit'
  );
  $attach_id = wp_insert_attachment( $attachment, $filename, 37 );
  // you must first include the image.php file
  // for the function wp_generate_attachment_metadata() to work
  require_once(ABSPATH . 'wp-admin/includes/image.php');
  $attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
  wp_update_attachment_metadata( $attach_id, $attach_data );
?>

Change Directory of Uploads

To change the directory of your uploads, you need to use the upload_dir filter. Yoast has a pretty good tutorial on how to do such.

add_filter('upload_dir', 'my_upload_dir');
$upload = wp_upload_dir();
remove_filter('upload_dir', 'my_upload_dir');

function my_upload_dir($upload) {
    $upload['subdir']   = '/sub-dir-to-use' . $upload['subdir'];
    $upload['path']     = $upload['basedir'] . $upload['subdir'];
    $upload['url']      = $upload['baseurl'] . $upload['subdir'];
    return $upload;
}

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)