# FAQ overflow

#### QUESTION

I am trying to do something similar to the above question. I am trying to make users post and upload images from front-end. I have already done the post form and its working.

I just followed and tried the answer posted by Robin I Knight upload-post-thumbnail-from-the-front-end. Sadly i couldn't get it to work. Is there anything i'm suppose to change or edit?

Thank you.

Now if you already have a form that handles the post submit you can simply add the upload file field input somewhere in your form:

<form ...
...
<input type="file" name="thumbnail" id="thumbnail">
...
...
</form>



make sure that your form has enctype="multipart/form-data" attribute.

then in your form processing script after you create the post (assuming that you are using wp_insert_post();) keep hold of the post ID in a new var:

$new_post = wp_insert_post($post_array);



            if (!function_exists('wp_generate_attachment_metadata')){
if ($_FILES) { foreach ($_FILES as $file =>$array) {
if ($_FILES[$file]['error'] !== UPLOAD_ERR_OK) {
return "upload error : " . $_FILES[$file]['error'];
$attach_id = media_handle_upload($file, $new_post ); } } if ($attach_id > 0){
update_post_meta($new_post,'_thumbnail_id',$attach_id);