skip to Main Content

I’m working on a PHP web application and having trouble displaying images in my admin dashboard. The images are stored in the directory /var/www/html/online_shop/public/photo_product, but they are not showing up on the page.

Here’s a summary of my setup and the issue:

Directory Structure:

  • Images are located in /var/www/html/online_shop/public/photo_product.
  • The URL path to the images is /photo_product/.

PHP Code:
In my admin_dashboard.php file, I am trying to display images with the following code:

<td><img src="/photo_product/<?php echo htmlspecialchars(basename($row['image'])); ?>" alt="Product Image" style="max-width: 80px; height: auto;"></td>

Troubleshooting Steps Taken:

  • Direct URL Access: I tried accessing the image URL directly in the browser (e.g., http://localhost/online_shop/public/Screenshot%202024-06-30%20074157.png), but the image did not load.
  • File Permissions: I ensured that the directory and image files have the correct permissions (755 for directories and 644 for files) and are owned by www-data.
  • File Existence: Verified that the image files exist in the specified directory and their filenames match the database entries.
  • Apache Configuration: Checked Apache configuration and .htaccess rules to ensure there are no restrictions blocking access to the image directory.
  • Browser Developer Tools: No relevant errors were found in the console or network tab.

Additional Information:

  • Apache web server version: [Apache/2.4.58 (Ubuntu)]
  • PHP version: [8.3.8]
  • The error logs do not indicate any issues related to the image serving.

Here’s a concise response to address the feedback and correct the information:


Thank you for pointing that out. I apologize for the confusion. Here’s a clearer update:

  1. Web Root Clarification: The web root is /var/www/html/online_shop/public/, so the root-relative URLs for images should indeed be /photo_product/....
  2. Apache Log Entries: The previous log entries were mistakenly included and are not relevant to the image issue. I’ll remove them.

I’ll update the question to reflect these points accurately. Thanks for your patience and assistance.


This response acknowledges the mistake, clarifies the web root, and commits to updating the question with the correct information.
Could anyone help me figure out why the images are not displaying? Are there any additional steps I should take to troubleshoot this issue?

Thank you!


2

Answers


  1. Assuming that your photos reside in
    /var/www/html/online_shop/public/photo_product

    and your admin page where you want the photos to appear resides in
    /var/www/html/online_shop/admin/admin.php

    You would use this code in your admin.php file:

    <img src='../public/photo_product/xyz.jpg' alt=''>
    
    Login or Signup to reply.
  2. I am trying this with a backgroud image don’t seem to work there in the for ground however I use

    <img src='./public/photo_product/image.jpg' />
    

    that works for me

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search