Reputation: 364
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";
}
Upvotes: 2
Views: 42
Reputation: 1164
Please add enctype="multipart/form-data"
to your form..
Upvotes: 4