dcdcdc
dcdcdc

Reputation: 263

wp_handle_upload issue Specified file failed upload test

When using the wp_handle_upload function it is returning the following error

 Array([error] => Specified file failed upload test.)

The code I am using is as follows

function dc_form_image_upload() {
    if ( ! function_exists( 'wp_handle_upload' ) ) {
        require_once( ABSPATH . 'wp-admin/includes/file.php' );
    }

    $uploadedfile = $_POST['file'];
    //print_r($uploadedfile);
    // die();

    $upload_overrides = array( 'test_form' => false );

    $movefile = wp_handle_upload( $uploadedfile, $upload_overrides ); 

    if ( $movefile && !isset( $movefile['error'] ) ) {
        echo "File is valid, and was successfully uploaded.\n";
        var_dump( $movefile);
    } else {
        /**
         * Error generated by _wp_handle_upload()
         * @see _wp_handle_upload() in wp-admin/includes/file.php
         */
        print_r($movefile);
    }
}

Standard admin media upload is working fine but this seems to be causing issues.

Can anyone give me some advice on this, have updated ini files and so on with no improvement.

Thanks.

Upvotes: 1

Views: 9056

Answers (1)

dcdcdc
dcdcdc

Reputation: 263

Problem was I was getting the following

$uploadedfile = $_POST['file']

instead of getting

$uploadedfile = $_FILES['file']

Upvotes: 5

Related Questions