# Displaying an image with include() or require()

**URL:** <https://www.phphelp.com/t/displaying-an-image-with-include-or-require/35690>\
**Category:** General PHP Help\
**Created:** [September 8, 2023, 7:41am UTC](https://www.phphelp.com/t/displaying-an-image-with-include-or-require/35690 "2023-09-08T07:41:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neelix](https://www.phphelp.com/letter_avatar_proxy/v4/letter/n/c5a1d2/32.png) [@Neelix](https://www.phphelp.com/u/Neelix)\
**Post date:** [September 8, 2023, 7:41am UTC](https://www.phphelp.com/t/displaying-an-image-with-include-or-require/35690/1 "2023-09-08T07:41:01Z")

</div>

I use require\_once() to display pages in a div.  
I wonder how I could use this to display images as well.

Here is my code :

```auto
require_once 'gauche_1.php'; 

		if ( (isset($_GET['page'])) && (isset($checkPage[$_GET['page']])) ) {
			require_once $checkPage[$_GET['page']];
        }
		    elseif ( (isset($_GET['category'])) && (isset($checkCategory[$_GET['category']])) ) {
	           readfile($checkCategory[$_GET['category']]);
	        
		} /* if $page has a value, include it */
		else {
			require_once 'milieu_1.php';
			echo '<script type="text/javascript" src="../js/music.js"></script>';
		}

```

my include.php :

```auto
$checkPage = array('Sommaire' => 'milieu_1.php',
	            'Nouveautes' => 'news/index.php' ...,
                    'Permis_D_Avoir_Du_Culot' => 'image.jpg');

```

Abd the html code :

```auto
<div class="licenseGallery">
                <a href="menu.php?category=Permis_D_Avoir_Du_Culot">
                    <img src="sweeties/permis/tn_permis_avoir_du_culot.jpg" alt="permis_avoir_du_culot.jpg">
                    <div class="licenseDescription">
                        permis_avoir_du_culot.jpg
                    </div>
                </a>
            </div>

```

---

<div class="post-metadata">

**Author:** ![Strider64](https://www.phphelp.com/user_avatar/www.phphelp.com/strider64/32/3161_2.png) [@Strider64](https://www.phphelp.com/u/Strider64)\
**Post date:** [September 8, 2023, 10:36am UTC](https://www.phphelp.com/t/displaying-an-image-with-include-or-require/35690/2 "2023-09-08T10:36:13Z")

</div>

🤔 I sure do not understand why you would want to do that in the first place? That is why there are functions or methods in the first place. If you want to make a script portable in this case the ability to display an image based on a condition then consider writing a **class** would be better suited to do it or even a **function** though has a little less flexibility as a class.

---

<div class="post-metadata">

**Author:** ![Neelix](https://www.phphelp.com/letter_avatar_proxy/v4/letter/n/c5a1d2/32.png) [@Neelix](https://www.phphelp.com/u/Neelix)\
**Post date:** [September 8, 2023, 1:58pm UTC](https://www.phphelp.com/t/displaying-an-image-with-include-or-require/35690/3 "2023-09-08T13:58:34Z")

</div>

Well, I’m a beginner, I don’t know how I can do that.
