Nothing found in uploads folder after wp_insert_attachment

file_put_contents($file, $msg_array);

should be

file_put_contents($wp_upload_dir['path'] ."https://wordpress.stackexchange.com/". basename( $file ), $msg_array);

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