Estou a tentar inserir uma imagem na base de dados mas quando clico upload imagem, da o seguinte erro: Warning: getimagesize(): Filename cannot be empty in /home/unn_w17015779/public_html/upload.php on line 9 File is not an image.;
Código HTML:
<body>
<?php include 'addDataAdmin.php';?>
<form name="ContactForm" action="addDataAdmin.php" method="POST" enctype="multipart/form-data" autocomplete="off" onsubmit="return ValidateContactForm();">
ISBN:<input type="text" name="ISBN">
Author's Name:<input type="text" name="Authorsname">
Title:<input type="text" name="Title">
Edition:<input type="number" name="edition" >
Year:<input type="text" name="year" onkeypress="return justNumber(event)" >
Category:
<select name="category" size="1">
<option value="computing">Computing</option>
<option value="Romance">Romance</option>
<option value="Fiction">Fiction</option>
<option value="Non-Fiction">Non-Fiction</option>
</select>
<br />
Publisher:<input type="text" name="publisher">
Quantity-in-stock:<input type="number" name="quantityinstock" >
Price:<input type="text" name="price" onkeypress="return justNumber(event)">
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit" formaction="/upload.php">
<input type="submit" value="Send" name="send">
<input type="reset" value="Clear">
</form>
código PHP:
<?php
include('config.php');
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
if (!empty($_FILES["fileToUpload"]["name"])) {
$Image =$conn->real_escape_string($_POST['Image']);
$sql="INSERT INTO books (Image) VALUES('$Image')";
if(mysqli_query($conn,$sql))
{
echo '<h3><font color="red">You have successfully updated </font></h3>';
}
else
{
echo 'Error';
echo $sql;
}
}
?>;
O que estou fazendo de errado? Obrigado desde já.
$_POST["Image"]
que não está no código apresentado.