I’m trying to upload an image to the database. I’m using getimagesize to check if it is an image. It is stored in a variable called $image_size. Even though this variable is inside the if statement, I keep getting an error that says:
Undefined variable: image_size in C:\xampp1\htdocs\admin.php on line 10
I believe the page is not supposed to worry about that variable unless we have $_POST [‘image’] being sent to the server. I do not know how I can fix this.
$status = '';
if (isset($_POST['image'])) {
$image = file_get_contents ($_FILES ['image']['tmp_name']);
$image_size = getimagesize ($_FILES ['image']['tmp_name']);
}
if ($image_size == 0) {
$status = "That is not an image. Please select an image.";
} else {
$sql = "UPDATE company_info SET
co_image = :co_image
WHERE id = 1";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':co_image', $image);
$stmt->execute();
$status = "Profile updated successfully!";
}