Ich versuche, ein Formular zu erstellen, wo ein Benutzer Bilder hochladen kann. Ich benutze PHP für die Validierung dieser Datei, um zu sehen, ob es eine Bilddatei ist oder nicht, aber ich bekomme einen Fehler. Der HTML-Code ist alsUndefinierter Index: Foto in C: xampp htdocs SW StudentWelafaremManagement version-1 registration.php on line 27
<form name="myform" class="col s12" method="POST" action="registration.php" onsubmit="return validateform1()" enctype="multipart/form-data">
<input class="file-path validate" type="text" name="photo" id="photo" />
<button class="btn waves-effect waves-light" type="submit" name="submit">Submit
<i class="material-icons right">send</i>
</button>
</form>
PHP-Code folgt, ist wie folgt. Ich hatte für alle verfügbaren Optionen getan .. Ich denke, die varaible in HTML-Form hier nicht zugreift, oder er Bild ist nicht
<?php //start php tag
define ("MAX_SIZE","1000000");
$hostname="localhost"; //local server name default localhost
$username="root"; //mysql username default is root.
$password=""; //blank if no password is set for mysql.
$database="studentwelafare"; //database name which you created
$con=mysqli_connect($hostname,$username,$password);
if(! $con)
{
die('Connection Failed'.mysql_error());
}
mysqli_select_db($con,$database);
if(isset($_REQUEST['submit'])!='')
{
if(empty($_FILES) || !isset($_FILES['photo']))
{
$folderName = "upload/photo";
$validExt = array("jpg", "png", "jpeg", "bmp", "gif");
// $photo=null;
$photo=$_FILES['photo']['tmp_name']; **//error comes here at photo variable name**
If($_REQUEST['photo']='')
{
Echo "please fill the empty field.";
}
elseif ($_FILES["photo"]["size"] <=0) { **// error at "photo" variable**
echo "image is not proper";
}
else{
$ext=strtolower(end(explode(".", $photo)));
if (!in_array($ext, $validExt)) {
# code..
echo "not a valid image";
}
else{
$photo=$_REQUEST['photo'];
$filePath=$folderName.rand(10000,990000).'_'.time().'.'.$ext;
if(move_uploaded_file($_FILES["photo"]["tmp_name"], $filePath))
{
$sql1="INSERT INTO students(photo)VALUES('".prepare_input($filePath) ."')";
$res1=mysqli_query($con,$sql1);
if($res1)
{
Echo " Student Registerd successfully";
}
else
{
Echo "There is some problem in inserting record";
}
mysqli_close($con);
}
}
}
}
else{
echo "enter image";
}
}
?>
Es sollte '$ _POST ['Foto']' sein, nicht '$ _REQUEST ['Foto']' ... – arkascha
Sogar ich änderte zu $ _POST ['Foto'] Fehler wird fortgesetzt .. –