I use the analog of this code https://codewithawa.com/posts/image-...mysql-database trying to load and output the image from the database to the page ... Allows you to choose, DOWNLOADS in dB, but returns the picture and shows that it is The type is broken, and the text that you enter - displays. Already the third day I can not understand what the error is ... I think that somewhere after the cycle, in the line where the output of the picture is, but everything seems to be correct ... Thanks in advance
<?php // Create database connection $db = mysqli_connect("localhost", "root", "", "image_upload"); // Initialize message variable $msg = ""; // If upload button is clicked ... if (isset($_POST['upload'])) { // Get image name $image = $_FILES['image']['name']; // Get text $image_text = mysqli_real_escape_string($db, $_POST['image_text']); // image file directory $target = "images/"."image_upload($image)"; $sql = "INSERT INTO images (image, image_text) VALUES ('$image', '$image_text')"; // execute query mysqli_query($db, $sql); if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) { $msg = "Image uploaded successfully"; }else{ $msg = "Failed to upload image"; } } $result = mysqli_query($db, "SELECT * FROM images"); ?> <!DOCTYPE html> <html> <head> <title>Image Upload</title> </head> <body> <div id="content"> <?php while (($row=$result->fetch_assoc())!=false) { echo '<div id="img_div"> <img src="images/'.$row["image"].'" > <p>'.$row['image_text'].'</p> </div>'; } ?> <form method="POST" action="kartinka.php" enctype="multipart/form-data"> <input type="hidden" name="size" value="1000000"> <div> <input type="file" name="image"> </div> <div> <textarea id="text" cols="40" rows="4" name="image_text" placeholder="Say something about this image..."></textarea> </div> <div> <button type="submit" name="upload">POST</button> </div> </form> </div> </body> </html>
$target = "images/"."image_upload($image)";what's in the images directory? Do you have a file calledimage_upload($image)? if so then you refer to just $ image. If not, this function should be$target = "images/".image_upload($image);- Ruslan Semenov