• Imagesusimueller

    (@susimueller)


    Hello,

    I am writing a membership area and want users to be able to upload images via forms. I am using the Code Snippets plugin for programming the interface.
    For testing purposes I have created a small form and file-handling snippet with following code:

    include ‘wp-admin/includes/file.php’;

    function to_upload_this(){

    if(!empty($_FILES[“upload_image”][“name”])){

    $fileType = pathinfo($_FILES[“upload_image”][“name”],PATHINFO_EXTENSION);
    $allowTypes = array(‘jpg’, ‘png’, ‘jpeg’, ‘svg’);
    if(in_array($fileType, $allowTypes)){
    //Upload file to the server
    $overrides = array( ‘test_form’ => false);
    $file = $_FILES[“upload_image”];
    $upload = wp_handle_upload($file, $overrides);
    if ( is_wp_error( $upload ) ) {
    // There was an error uploading the image.
    echo “an error”;
    print_r($upload);
    } else {
    // The image was uploaded successfully!
    echo “no error”;
    print_r($upload);
    }
    echo ‘Path is allowed.’;

    }else{
    echo ‘Sorry, only JPG, JPEG, PNG & SVG files are allowed to upload.’;
    }
    }
    ?>
    <form method=”post” enctype=”multipart/form-data”>
    <input type=’file’ name=”upload_image”>

    <input type=”submit” name=”submit” value=”Submit”>
    </form>
    <?php

    return;
    }

    add_shortcode( ‘tests’,’to_upload_this’ );

    The website uses php 7.3.25 and wordpress 5.3.1 and Strato is the host. And when I display phpinfo() it states that “file_uploads” is “on”.

    It would be really nice to get some help fixing this and if you need any further information please ask.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author ImageShea Bunge

    (@bungeshea)

    Have you tried the code you have out? What is not working about it?

    Thread Starter Imagesusimueller

    (@susimueller)

    Well it would be nice if it worked.
    If I execute it it only states:

    no errorArray ( [error] => Specified file failed upload test. ) Path is allowed.

    And I can’t find the image in the wordpress media center.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘wp_handle_upload error:”Specified file failed upload test.”’ is closed to new replies.