Jump to content

How to display image from Database?


KaiSheng

Recommended Posts

Firstly, i wanna say that all my codes were working perfectly fine in a localhost.

After that, transfers to a domain, putting the website online.

My codes do not function properly after that.

What i want to achieve is to display the images i have uploaded into the database, from the folder called image.

 

I'll show code.

This is the page where the process of uploading takes place.

if ((($_FILES["picture"]["type"] == "image/gif")
|| ($_FILES["picture"]["type"] == "image/jpeg")
|| ($_FILES["picture"]["type"] == "image/jpg")
|| ($_FILES["picture"]["type"] == "image/pjpeg")
|| ($_FILES["picture"]["type"] == "image/x-png")
|| ($_FILES["picture"]["type"] == "image/png"))
        
)
{
 if ($_FILES["picture"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["picture"]["error"] . "<br />";
    }
    else
    {
    echo "Upload: " . $_FILES["picture"]["name"] . "<br />";
    echo "Type: " . $_FILES["picture"]["type"] . "<br />";
    echo "Size: " . ($_FILES["picture"]["size"]) . " Kb<br />";
    echo "Temp file: " . $_FILES["picture"]["tmp_name"] . "<br />";

    if (file_exists("image/" . $_FILES["picture"]["name"]))
    {
    echo $_FILES["picture"]["name"] . " already exists. ";
    }
   else
    {
    move_uploaded_file($_FILES["picture"]["tmp_name"],
    "image/" . $_FILES["picture"]["name"]);
    echo "Stored in: " . "../image/" . $_FILES["picture"]["name"];
    }
    }
    }
    else
    {
    echo "Invalid file";
    }

---

This is the viewing of the displayed images.

while ($row = mysqli_fetch_array($result)) {
                        $id = $row['id'];
                        $username = $row['username'];
                        $category = $row ['category'];
                        $description = $row['description'];
                        $date_found = $row['date_found'];
                        
                        $picture = $row['picture'];
                        $image = "<img src='image/$picture' />";
                        $date_submitted = $row['date_submitted'];
                        $outlet = $row['outlet'];
                        $item_match = $row['item_match'];
                        ?>
                        <tr>
                          
                            <td><?php echo $category; ?></td>
                            <td><?php echo $description; ?></td>
                            <td><?php echo $date_found; ?></td>
                            <td><img src=""<?php echo $picture;?> height="100" width="100"</td>
                            <td><?php echo $date_submitted; ?></td>
                            <td><?php echo $outlet; ?></td>
                            <td><?php echo $username; ?></td>
                            <td><?php echo $item_match; ?></td>

It is not working for the display area.

Can someone help? thanks.

Link to comment
Share on other sites

Not working refers to no image displayed.

There are no errors shown.

I think it's something related to the echo of the image line, however i searched and tried all kinds of <img src code, it doesn't work. (Or maybe the path.. but i have no idea how to change it.)

I have a folder called LN, inside LN is all my codes, inside LN also contains the folder called image.

I want to display the picture inside the folder called image.

Link to comment
Share on other sites

Perhaps the image tag isn't pointing to the right folder. Have you tried using root-relative links?

 

$image = "<img src='/image/$picture'  height='100' width='100' />";

 

Note that I added the slash before the "image" folder. Of course, your image folder may not be in the root director. You'll need to modify the path to match where the images are being uploaded.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.