Support

Account

Home Forums General Issues Uploading Image/File on the front-end Reply To: Uploading Image/File on the front-end

  • This is what I did. Thanks.

    //Upload la photo dans le dossier
    require_once(ABSPATH.’wp-admin/includes/file.php’);
    $uploadedfile = $_FILES[‘photo’];
    $movefile = wp_handle_upload($uploadedfile, array(‘test_form’ => false));

    //On sauvegarde la photo dans le média library
    if ($movefile) {
    $wp_upload_dir = wp_upload_dir();
    $attachment = array(
    ‘guid’ => $wp_upload_dir[‘url’].’/’.basename($movefile[‘file’]),
    ‘post_mime_type’ => $movefile[‘type’],
    ‘post_title’ => preg_replace(‘/\.[^.]+$/’, ”, basename($movefile[‘file’])),
    ‘post_content’ => ”,
    ‘post_status’ => ‘inherit’
    );
    $attach_id = wp_insert_attachment($attachment, $movefile[‘file’]);

    update_field(‘photo’, $attach_id, ‘user_’.$current_user->ID);
    }