How to Display Image in PHP from Folder/Directory

Here, I have to show the code display image in PHP from folder. As well as, might get image from the database.

After that, you might see some examples of the list of all images in folder and subfolders from the directory and folder using PHP.

echo "<img src='images/image-name.JPG' >";  

Display Image in Php from Folder

Hence, I have to show some methods of displaying image from the directory folder path.

 <title>display image</title>
 <p>Here in your form and text</p>
	echo "<img src='image-name.png' >"; 


Thus, we have to use echo to print the image. this is the keywords of Php. Php provides this for print an integer and string values.

After that, Html syntax for displaying an image. now, as you know put the image name from the main folder.

As a rule, in the image, there is a source option. you can add image name make sure must know your image folder path in your project.

So, if you have a folder and subfolder inside the folder available number of images. therefore, pick the specific image name and copy image name.

for example, you can see have to mention an example of image source src=’image-name.png’ this is a direct image path.

So, if the image in directory or folder and subfolder then put this code src=’folderName/SubfolderName/image-name.png’. Make sure you understand the folder directory and subfolder directory.

Similarly, list all images in folder and subfolders you can get an image and fetch the image from a folder.

display image in php from folder

How to Display Image from Database in Php

Similarly, we created an above code for retrieve images from directory same as getting the image name from the database in PHP and retrieve an image.

 <title>display image</title>
 <p>Here in your form and text</p>
	$conn = mysqli_connect("localhost", "root", "", "customer");
	$image_details  = mysqli_query($conn, "SELECT * FROM customer_table");
     while ($row = mysqli_fetch_array($image_details)) {     
      	echo "<img src='images/".$row['imagename']."' >";   


Here, you saw a display image from the database in Php. This the main method to apply this code on your Html code.

Firstly, create a connection between the database and then get the image details. Also, check out this code How to Insert JSON data into MySQL using PHP

After that, added a MySQL select query for fetch the image from MySQL database.

Afterward, this is the keyword of SQL which is provided for array $row[‘image name’].

Now, in this image name, you can replace your own field name in your database as you defined.

Image is not Displaying in Php

So, sometimes image not display. they showing error rather than blank.

So, what do you want firstly, you can check the path. it means directory and folder name.

If it’s correct then check your image name as well as, check image extension likewise, jpg or png check out image and image name.

If both are the same image might display this is the right to wait. make sure images have available are there and check your database image name and field name.

Hence, print your image details array which you get for fetch image from the database.

Also, check both names otherwise one time can put direct image because sometimes comes error from Html syntax.

The main method read your warning message and follow line number and insertions what saying.

If syntax error you can put out our image displaying syntax code.


Finally, view all codes method best method of displaying an image from the folder and directory with example.

If any query checks and asks us in the comment section. Also, have main relative similar topic How to Store and Retrieve Image from database in Php


  1. Thanks for your marvelous posting! I seriously
    enjoyed reading it, you might be a great author.
    I will always bookmark your blog and will often come back later on. I want to encourage you continue your great posts, have a nice morning!

  2. You really make it seem so easy with your presentation but I find this
    topic to be really something that I think I would never understand.
    It seems too complex and extremely broad for me. I am looking forward for your next post, I’ll try to get the hang of it!

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts

Related Post

Submit Form without Page Refresh using Ajax jQuery PHP

Here, we are going to start about submit a form without page refresh using Ajax jQuery and Php with the example. Also, explain and given some code to ajax serialize form data example without reloading the page. As well as, submit form and show results on the same page without a refresh. Thus, showing the […]

Read more

How to Store and Retrieve Image from database in Php

So, I am going to explain and showing you the best method to store and retrieve image from database in PHP. And about with the code of upload and fetch an image from the MySQL database using PHP. As well as, when the insert image in MySQL database then with upload image a specific folder. […]

Read more

How to Insert JSON data into MySQL using PHP

You might see every method to insert JSON data into MySQL using PHP. So, we explain about insert multiple JSON data with an example of code in PHP. Here, we implement all points step by step using PHP. Also, you can see how to store JSON data in the MySQL database with an example. How […]

Read more