How to Add an Image in a PHP File


PHP has an "echo" command that lets you write any HTML element and data to the reader's browser, including the image tag. Writing images through PHP allows you to create dynamically shown images on your website. For instance, when you have items you want to display with images retrieved from a database. You write out the tag using the PHP "echo" statement.

  • Right-click the PHP file on your web development computer. Select "Open With," then double-click "Notepad" to open the file in your text editor.

  • Type your PHP open and closing tags. These tags contain all PHP code, so your web server knows to execute the code instead of displaying it as text. Type the following PHP tags:

    <?php ?>

  • Type the "echo" statement that displays the image from PHP. Type the following code:

    echo "<img src='myimage.jpg'>";

    Replace "myimage.jpg" with your own image file on your Web server.

  • Press "Ctrl" and "S." Open the file in your Web browser to test the code and view the image placement.

Related Searches


Promoted By Zergnet


You May Also Like

Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

Is DIY in your DNA? Become part of our maker community.
Submit Your Work!