I am trying to upload image Code to upload image is given below :
if (!isset($_POST['submit'])) {
if (isset($_FILES['imageUpload'])) {
// image upload
$target_dir = "C:/wamp64/www/images/";
$target_file = $target_dir . basename($_FILES["imageUpload"]["name"]);
echo 'Your tmp location of img file is ' . $_FILES['imageUpload']['tmp_name'] . '<br>';
$imagetmp = addslashes(file_get_contents($_FILES['imageUpload']['tmp_name']));
if (isset($_FILES['imageUpload'])) {
if (move_uploaded_file($_FILES["imageUpload"]["tmp_name"], $target_file)) {
echo "The file " . basename($_FILES["imageUpload"]["name"]) . " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
$image = basename($_FILES["imageUpload"]["name"], ".jpg");
$imagename = addslashes($_FILES['imageUpload']['name']);
}
$query = "INSERT INTO `form_details` (firstname,secondname,location,designation,fileno,doa,doj,cardtype1,cardcolor,cardtype2,door1,door2,door3,door4,door5,door6,door7,door8,door9,door10,door11,door12,imagetmp,imagename) VALUES('$firstname','$secondname','$location','$designation','$fileno','$doa','$doj','$cardtype1','$cardcolor','$cardtype2','$door1','$door2','$door3','$door4','$door5','$door6','$door7','$door8','$door9','$door10','$door11','$door12','$imagetmp','$imagename')"; //query
if (mysqli_query($connect, $query)) { //check query executed or not
echo 'inserted' . '<br>';
} else {
echo "problem occur" . mysqli_error($connect);
}
} else {
echo "form values are required";
}
Undefined index: imageUpload in
file_get_contents(): Filename cannot be empty
are the two errors.
I have tried isset
, it doesn't work . print_r($_FILES);
output is blank Array ( )
. It means there is no file uploaded but I have uploaded the file.
I am not able to add picture to a given location
I am able to execute the query as successful but it doesn't upload the pic to the database .
My code for photo
<div class="form-inline">
<label for="Passportcopy">Passport Copy</label>
<input type="file" class="form-control" name="imageUpload"/>
</div>
Try removing !
in the first isset
if(isset($_POST['submit'])){
//...other codes
}