2

So I managed to write a peice of code that allows me to upload a zip file, im not even sure where it gets uploaded too, and I am doing it on my localhost with apache in control (www-data). the code is as follows:

public function upload_file(array $file){
    add_filter('upload_mimes', array($this, accepted_mime_type));

    if(wp_handle_upload($file, array('test_form' => false))){
        var_dump(wp_handle_upload($file, array('test_form' => false)));
    }else{
        $this->error('Oops!', 'Something went wrong with the upload. Please try again.');
    }       
}

the error I get is: Specified file failed upload test

Im not sure whats going on, this is localhost.

1
  • What is going on is that you are calling wp_handle_upload() twice and the second time is failing. – Otto Sep 14 '14 at 11:57
1

The error you are seeing is coming from wp_handle_upload():

// A properly uploaded file will pass this test. There should be no reason to override this one.
if ( $test_upload && ! @ is_uploaded_file( $file['tmp_name'] ) )
    return call_user_func($upload_error_handler, $file, __( 'Specified file failed upload test.' ));

I am not sure about your context, but what you are trying to do seems to not be POST upload and as such fails is_uploaded_file() check.

2
  • What do you mean its not a POST? how else would you call this function other then hitting submit on a form containing a file? this error does not seem clear, please explain further, and or show what you would write to make it pass. I did a var dump on is_uploaded_file($file['tmp_name']) and I got a bool true, which means that is was uploaded via HTTP POST. Turns out the second option should be 'false', as it was $test_form that was freaking out – TheWebs May 28 '13 at 22:59
  • Hm, actually it seems to be checking for ! so not POST upload... Sorry, as much sense as I could make of it from quick look (not my area). – Rarst May 28 '13 at 23:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.