Ph33ly
Ph33ly

Reputation: 693

PHP image file upload error

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?

Upvotes: 0

Views: 153

Answers (2)

ilikesleeping
ilikesleeping

Reputation: 609

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

Upvotes: 2

Drakes
Drakes

Reputation: 23660

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

Upvotes: 1

Related Questions