Support » Fixing WordPress » Multi-Image Frontend Uploader

  • Currently I’m working on a multiple images file uploader on wordpress and its all build around the front end. Its currently making the info for the image but won’t actually upload the file to the uploads folder.

    <?php
    $images = $_POST[‘images’];

    //Upload Images
    if($images){
    require_once(ABSPATH . ‘wp-load.php’);
    require_once(ABSPATH . ‘wp-admin/includes/image.php’);
    require_once(ABSPATH . ‘wp-admin/includes/file.php’);
    require_once(ABSPATH . ‘wp-admin/includes/media.php’);

    foreach ($images as $filename){

    $wp_filetype = wp_check_filetype(basename($filename));
    $wp_upload_dir = wp_upload_dir();
    $attachment = array(
    ‘guid’ => $wp_upload_dir[‘subdir’] .’/’. _wp_relative_upload_path( $filename ),
    ‘post_mime_type’ => $wp_filetype[‘type’],
    ‘post_title’ => preg_replace(‘/\.[^.]+$/’, ”, basename($filename)) . $post_id,
    ‘post_content’ => ”,
    ‘post_status’ => ‘inherit’
    );
    $image_meta = $wp_upload_dir[‘subdir’] .’/’. $filename;
    $attach_id = wp_insert_attachment( $attachment, $image_meta, $post_id );

    $attach_data = wp_generate_attachment_metadata( $attach_id, $file_loc );
    wp_update_attachment_metadata( $attach_id, $attach_data );
    add_post_meta($post_id, ‘_images’, $attach_id);
    }
    }
    ?>
    <form method=”post” action=”” enctype=”multipart/form-data”>
    <input type=”file” name=”images[]” multiple>
    </form>

    I have no clue whats wrong with this. Any help?

  • The topic ‘Multi-Image Frontend Uploader’ is closed to new replies.