Я создаю загрузчик изображений, с помощью которого я хотел бы загрузить свое изображение на сервер и заменить старый URL-адрес изображения в базе данных новым. Часть загрузки работает отлично, однако я не могу получить imageURL в базе данных. Может кто-нибудь взглянуть на мой код и сказать мне, где я делаю неправильно?загрузить изображение на сервер и сохранить URL-адрес сервера
<?php
$target_dir = "media/images/";
$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["uploadImage"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if ($check != false) {
echo "File is an image - " .$check["mime"]. ".";
$uploadOK = 1;
} else {
echo "File not an image";
$uploadOK = 0;
}
}
// check if file exists
if (file_exists($target_file)) {
echo "sorry File exists";
$uploadOK = 0;
}
// check fle size
if ($_FILES["fileToUpload"]["size"] > 5000000) {
echo "Sorry your file is too large.";
$uploadOK = 0;
}
// Allow certain file formats
if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") {
echo "sorry, only JPG, JPEG, PNG and GIF files allowed.";
$uploadOK == 0;
}
// check if $uploadOK is set 0 by an error
if ($uploadOK == 0) {
echo "Sorry your file was not uploaded.";
// if everything is ok try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename($_FILES["fileToUpload"]["name"]). " has been uploaded.";
include 'connect.php';
$stmt = $conn->prepare("INSERT INTO image(name,imageURL, image_cat_id, AlbumID) VALUES (home1, ?, 8, 0)");
$stmt->bind_param('s', $target_file);
$stmt->execute();
$stmt->close();
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
Результат на успешной загрузки:
File is an image - image/png.The file arrowdown_51.png has been uploaded. Fatal error: Call to a member function bind_param() on boolean in C:\xampp\htdocs\WebDevelopment\Mosta Dynamic\CMS\upload.php on line 47
Привет спасибо за Ваш ответ - попробовал ваше решение и ушла ошибка, однако база данных не обновляется. – Chri