2

I'm having a hard time using a HTML file input. Everytime i vardump the $_FILES array i can see it is completely empty: array(0) { } and the following notices:

Notice: Undefined index: upload in C:\xampp\htdocs\pages\addproperty.sfwp on line 29

Notice: Undefined index: upload in C:\xampp\htdocs\pages\addproperty.sfwp on line 31

Notice: Undefined index: upload in C:\xampp\htdocs\pages\addproperty.sfwp on line 36`

Could someone have a look at my code?

HTML:

<input type="file" class="form-control" placeholder="Afbeelding" name="upload">

PHP:

$insert = $Properties->createProperty($catid,$typeid, $title, $price, $adressline1, $adressline2, $postalcode, $city, $province, $country, $sellerid, $avbedrooms, $avbathrooms, $avparkingspots, $claimsize, $livesize, $details);
    if($insert){
        echo $insert;
        var_dump($_FILES);
            $uploaddir = 'usrContent/';
            $uploadfile = $uploaddir . "IMG_".$insert."_01.".end((explode(".", $_FILES['upload']['name'])));

            $ext = end((explode(".", $_FILES['upload']['name'])));

            if($ext != "png" || $ext != "jpeg" || $ext != "jpg"){

            }
            if (move_uploaded_file($_FILES['upload']['tmp_name'], $uploadfile)) {
                echo "File is valid, and was successfully uploaded.\n";
            } else {
                echo "Upload went Wrong!\n";
            }
    }else{
        echo"2";
    }
2
  • 2
    Are you sure about enctype="multipart/form-data" added to form Commented Feb 9, 2015 at 12:26
  • Thankyou Sir, I didn't knew it was that important but it solved my issue. Thankyou very much Commented Feb 9, 2015 at 12:29

1 Answer 1

4

Please add enctype="multipart/form-data" to your form..

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

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.