Image not displayed


#1

Hi
i learn php from a youtube tutorial and follow them.
now i work an a gallery ever thing seems ok.
But i can’t display the image from the upload folder. I check this with var_dump() and ever thing is there but not displayed in the browser.

I hope my explanations is not too confused.

many thank in advanced

====================================================================
index.php

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="css/main.css">
    <title>Gallery</title>
  </head>
  <body>
      <div class="wrapper">
        <h2>Gallery</h2>

        <div class="gallery_container">
          <?php
          include_once "includes/dbh.inc.php";


          $sql = "SELECT * FROM gallery ORDER BY orderGallery Desc;";
          $stmt = mysqli_stmt_init($conn);
          if (!mysqli_stmt_prepare($stmt, $sql)) {
              echo"SQL statment failed!";
          } else {
              mysqli_stmt_execute($stmt);
              $result = mysqli_stmt_get_result($stmt);

              while ($row = mysqli_fetch_assoc($result)) {
                  echo '<a href="#">
                <div style="background-img: url(includes/uploads '.$row['imgFullNameGallery'].');"></div>

                <h3>'.$row["titelGallery"].'</h3>
                <p>'.$row["descGallery"].'</p>
              </a>';
                  
              }
          }

          ?>
        </div>

        <div class="gallery_uploads">
          <form action="includes/gallery_uploads.inc.php" method="post" enctype="multipart/form-data">
            <input type="text" name="filename" placeholder="File name...">
            <br>
            <input type="text" name="filetitle" placeholder="Image title...">
            <br>
            <input type="text" name="filedesc" placeholder="Image description...">
            <br>
            <input type="file" name="file" >
            <button type="submit" name="submit">UPLOAD</button>

        </form>
        </div>
  </div>
  </body>
</html>

========================================================================
gallery_upload.inc.php

<?php
if (isset($_POST['submit'])) {
    $newFilename = $_POST['filename'];
    if (empty($newFilename)) {
        $newFilename = "gallery";
    } else {
        $newFilename = strtolower(str_replace(" ", "-", $newFilename));
    }
    $imgTitle = $_POST['filetitle'];
    $imgDesc = $_POST['filedesc'];


    $file = $_FILES["file"];

    $fileName = $_FILES["file"]["name"];
    $fileTmpName = $_FILES["file"]["tmp_name"];
    $fileSize = $_FILES["file"]["size"];
    $fileError = $_FILES["file"]["error"];
    $fileType = $_FILES["file"]["type"];

    $fileExt = explode(".", $fileName);
    $fileActualExt = strtolower(end($fileExt));

    $allowed = array("jpg", "jpeg", "png");
    if (in_array($fileActualExt, $allowed)) {
        if ($fileError === 0) {
            if ($fileSize < 5000000) {
                $imageFullName = $newFilename.".".uniqid("", true).".".$fileActualExt;
                $fileDestination = 'uploads/'.$imageFullName;

                include_once "dbh.inc.php";

                if (empty($imgTitle) ||empty($imgDesc)) {
                    header("Location: ../index.php?upload=empty");
                    exit();
                } else {
                    $sql = "SELECT * FROM gallery;";
                    $stmt = mysqli_stmt_init($conn);

                    if (!mysqli_stmt_prepare($stmt, $sql)) {
                        echo"SQL statment failed1!";
                    } else {
                        mysqli_stmt_execute($stmt);
                        $result = mysqli_stmt_get_result($stmt);
                        $rowCount = mysqli_num_rows($result);
                        $setImageOrder = $rowCount +1;

                        $sql = "INSERT INTO gallery (titelGallery, descGallery, imgFullNameGallery, orderGallery) Values (?, ?, ?, ?);";

                        if (!mysqli_stmt_prepare($stmt, $sql)) {
                            echo"SQL statment failed!2";
                        } else {
                            mysqli_stmt_bind_param($stmt, "ssss", $imgTitle, $imgDesc, $imageFullName, $setImageOrder);
                            mysqli_stmt_execute($stmt);

                            move_uploaded_file($fileTmpName, $fileDestination);
                            header("Location: ../index.php?uploadsuccess");
                        }
                    }
                }


                            } else {
                echo "Your file is too big!";
            }
        } else {
            echo "There was an error uploading your file!";
        }
    } else {
        echo "You ca not upload files of this type!";
    }
}

============================================================================
main.css

@CHARSET "utf-8";

html, body {
  margin: 0px;
  padding: 0px;
  width: 100%;
  background-color: gray;
}

div, header, section, nav, aside, article, footer, hgroup, details, figcaption, figure, menu {
  display: block;
}

.wrapper {
  margin: 10px auto;
  width: 960px;
  background-color: blue;
}

.gallery_container {
  display: flex;
  flex-wrap: wrap;
  padding: 10px;
}

.gallery_container a {
  margin-left: auto;
  margin-right: auto;
}

.gallery_container a:hover {
  opacity: 0.8;
}

.gallery_container a div {
  border: 1px solid grey;
  width: 100%;
  height: 200px;
}

.gallery_uploads {
  padding: 10px;
  width: 300px;
  margin-left: auto;
  margin-right: auto;
}

h2 {
  font: 22px serif;
  color: #111;
  text-align: center;
  margin: 0px;
}

h3 {
  font: 18px serif;
  color: #111;
  margin: 1px;
  text-align: center;
}

p {
  color: black;
  font: 14px serif;
  margin-top: 3px;
  text-align: center;
}

#2

There is a space in there that shouldn’t be.


#3

hi astonecipher
thank you that you answer me i look the tutorial again and there was a space after “includes/upload” i change that but is not working. If you find the time you can give a tip more.

Thank you!!

#4

Does the name of the file have a slash in it? based on the url, you may want to add an additional slash after the ‘uploads’.

includes/uploads/


#5

Hi it’s me again
i find a solution for the problem
<img src=“includes/uploads/’.$row[“imgFullNameGallery”].’”>
it works

many thanks for your help