I’ve the next problem: The code to validate the name, address and email works, but to validate the image does not work and do not know why that happens. As always prints “Select an image”
I did a test and set the line to print the temporary name of the image with “print $photo” but nothing prints!
form.php
<form id="formregister" name="formregister" action="register.php" method="post">
<input id="name" name="name" type="text"/>
<input id="address" name="address" type="text"/>
<input id="email" name="email" type="email" />
<input id="photouser" name="imguser" type="file"/>
<input id="bregister" name="bregister" type="submit" value="Registrer"/>
</form>
register.php
..............
$name = $_POST['name'];
$address = $_POST['address'];
$email = $_POST['email'];
$photo = $_FILES['imguser']['tmp_name'];
$errors = array();
if(!isset($photo)) {
$errors[] = "Select an image";
} else {
$fototemp = addslashes(file_get_contents($_FILES['imguser']['tmp_name']));
$fotoname = addslashes($_FILES['imguser']['name']);
$fotosize = getimagesize($_FILES['imguser']['tmp_name']);
if ($fotosize == false) {
$errors[] = "Invalid format";
}
}
//Code to validate the other fields (name, address, email)
....................
You are missing the proper
enctypefor file uploads on your form. It should beenctype='multipart/form-data'Rather than accessing the secondary
tmp_namekey directly, test if it is set first to avoid undefined index notices: