I'm in need of some help! :)
What I'm trying to do is let a user create a post from the front end. With a preview window of how the post will look like when published. This I have already accomplished. Now I'm trying to allow the user to upload a image directly into the media library. This upload needs to happen as soon as the user has chosen the file with the follow code:
<form method=post action=# enctype=multipart/form-data >
<input type=file name=featured_image>
</form>
I don't want any page load, is there a way to get the file without using a submit button?
Also how do I handle the actual file upload, my google skills found this function:
function insert_attachment($file_handler,$post_id,$setthumb='false') {
// check to make sure its a successful upload
if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false();
require_once(ABSPATH . wp-admin . '/includes/image.php');
require_once(ABSPATH . wp-admin . '/includes/file.php');
require_once(ABSPATH . wp-admin . '/includes/media.php');
$attach_id = media_handle_upload( $file_handler, $post_id );
if ($setthumb) update_post_meta($post_id,'_thumbnail_id',$attach_id);
return $attach_id;
}
But this function hooks the upload to a post, I just want it to go straight into the library without being connected to a post. Also I assume the $file_handler is the name of the form? I also assume that $_FILES doesn't exists unless the user has clicked a submit button.
I'm prolly way off here, talking out of my ass. So any help would be appriciated. Any WP-gurus available? :D