0

In my form I have

<td>Boiler Image:</td>
    <input type ="hidden" name="MAX_FILE_SIZE" value="1000000" />
    <td><input type="file" name="boiler_image" id="boiler_image" /></td>

In my php code I have

if (is_uploaded_file($_FILES['boiler_image']['twp_name'])){
        if (!move_uploaded_file($_FILES['boiler_image']['twp_name'], $upfile)){
            echo 'Problem: Could not move file to destination directory';
            exit;
        }
    }
    else {
        echo 'Problem: Possible file upload attack. Filename: ';
        echo $_FILES['boiler_image']['name'];
        exit;
    }

Whenever I try to upload an image I get 'Problem: Possible file upload attack. Filename:' Did I happen to set up the input form incorrectly?

7
  • 2
    Shouldn't both 2 occurrences of twp_name be tmp_name? Commented Apr 15, 2015 at 23:21
  • Exactly what @Mex said, it's tmp_name. Commented Apr 15, 2015 at 23:22
  • change ['twp_name'] to ['tmp_name'] in both places Commented Apr 15, 2015 at 23:23
  • Thanks for the responses! I fixed ['tmp_name'] but unfortunately I still seem to be getting the same error as before Commented Apr 15, 2015 at 23:33
  • possible duplicate of php file upload problem Commented Apr 15, 2015 at 23:35

2 Answers 2

2

Ensure you have set the enctype="multipart/form-data" attribute on your form. It is required for all forms that have file uploads.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! looks like this was my issue
Great! FYI If an answer works for you, you can hit the "accept answer" button on the left if you like :)
1

The temporary filename of the file in which the uploaded file was stored on the server is located at key "tmp_name". So, change your instances of twp_name to tmp_name.

$_FILES['boiler_image']['tmp_name']

Ref: http://php.net/manual/en/features.file-upload.post-method.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.