Multi-Image Frontend Uploader (1 post)

  1. JonLimitless
    Posted 3 years ago #

    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.

    $images = $_POST['images'];

    //Upload 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>

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

Topic Closed

This topic has been closed to new replies.

About this Topic