Estou a tentar inserir uma imagem na base de dados, mas esta dando erro.
Código HTML:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit" formaction="/upload.php">
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á.