Ik ben bezig met een website en daar wil ik een foto in uploaden. Ik ben al aardig ver met de code ik blijf alleen een undefined index fout krijgen. Is er iemand die mij hier mee kan helpen? de volgende foutcodes krijg ik:
Notice: Undefined index: foto in C:\xampp\htdocs\website\auto-voegtoe.php on line 101
Notice: Undefined index: foto in C:\xampp\htdocs\website\auto-voegtoe.php on line 102
Notice: Undefined index: foto in C:\xampp\htdocs\website\auto-voegtoe.php on line 103
Notice: Undefined index: foto in C:\xampp\htdocs\website\auto-voegtoe.php on line 104
Notice: Undefined index: foto in C:\xampp\htdocs\website\auto-voegtoe.php on line 105
Dit is mijn code:
<?php
// Is er op de verzendbutton gedrukt?
if (isset($_POST ['auto-voegtoe-submit']))
{
// Post variabelen
$auto_naam = $_POST ['naam'];
$auto_omschrijving = $_POST ['omschrijving'];
$auto_prijs = $_POST ['prijs'];
// Verwerk upload image
$errors = array(); //Fouten array
$foto_naam = $_FILES ['foto']['name'];
$foto_grootte = $_FILES ['foto']['size'];
$foto_tmp = $_FILES ['foto']['tmp_name']; //Tijdelijke opslag op webserver
$foto_type = $_FILES ['foto']['type'];
$foto_ext = strtolower (end (explode ('.', $_FILES ['foto']['name'])));
//toegestane bestandsextensies
$extensions = array ('jpeg', 'jpg', 'png');
//Check bestandsextensies
if ( in_array($foto_ext, $extensions) === false )
{
$errors[] ='Extensie niet toegestaan alleen JPEG of PNG.' ;
}
// Check bestandsgrootte
if ($foto_grootte >= 2097152)
{
$errors[] ='Bestand mag niet groter zijn dan 2MB.' ;
}
// Check of fouten aanwezig zijn
if ( empty($errors) === true)
{
// Maak images directory getcwd() = get current working directory
$foto_dir = getcwd() . '/autos/';
//Verplaats van tijdelijke opslag op server
// naar definitieve directory met juiste naam
move_uploaded_file ($foto_tmp, $foto_dir . $foto_naam) ;
// CHECK NU OP MYSQL
if (FALSE !== ($db_connect =@mysql_connect('127.0.0.1', 'root','')) || die (mysql_error() ) )
// Functie die() stopt uitvoer script als connectie met server mislukt
{
// CHECK NU OP DATABASE
if (FALSE !== @mysql_select_db ('autobedrijf')
|| die(mysql_error() )
){
//succesvolle connectie met database, maak nu de SQL query
$query = "
INSERT INTO auto (naam, omschrijving, prijs, foto)
VALUES ('$auto_naam','$auto_omschrijving', $auto_prijs,'./images/$foto_naam'); " ;
//Voer de MySQL query uit
if ( FALSE !== @mysql_query($query) || die(mysql_error())
)
{ // echo '<p> Gegevens succesvol in de database ingevoerd! </h3>'; //Klaar
header ("Location: index.php");
}
}
}
}
}
?>
5.014 views