SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist english-test.net's Avatar
    Join Date
    Jul 2003
    Location
    Leipzig, Germany, Germany
    Posts
    438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    insert an image into index.php file

    Hi, how do I insert an image into my index.php file? As of now it looks like this:


    <?php
    echo ("Hello");
    ?>


    Many thanks,
    Torsten

  2. #2
    SitePoint Evangelist
    Join Date
    Apr 2009
    Location
    South Carolina
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You insert images with php in much the same way you insert images with html.

    If you are wanting to stay in php, echo the html code.
    PHP Code:
    <?php
    echo 
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <img src="/images/image1.png" width="280" height="125" title="Logo of a company" alt="Logo of a company" />

    </html>
    '
    ;
    ?>
    I left out a lot of the html code that should be on most pages.

    If you just want to use a little php, you can just use short bits of php inserted where you need it.

    Some html pages actually using the php include to create parts of the website that are repeated on many (or all) pages. If you want to include an image on every page, copy the code you use on your page and save it to a include folder besing sure to start and stop the code with the php start and stop tags.

    Then locate the place you want the image to show on your webpage, and use code similar to this:
    <?php include($_SERVER['DOCUMENT_ROOT']."/include/logo.php") ?>

    If that was not what you are looking for, try restating your question.
    Each day is a learning experience.

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2006
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The server will compile the php code , and send it along with your php file.

    So you can just
    Code:
    <html><head><title><?php echo "cool title";?></title></head>
    <body
    <?php 
    $image_url='https://www.google.com/intl/en_com/images/srpr/logo3w.png';
    ?>
    
    <img src="<?php echo $image_url;?>">
    
    <br><h1>Got me?</h1>

  4. #4
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by english-test.net View Post
    Hi, how do I insert an image into my index.php file? As of now it looks like this:


    <?php
    echo ("Hello");
    ?>


    Many thanks,
    Torsten
    A php file can contain a combination of html, css and javascript. If your web page file name has a .php extension, the web page is first sent to the "php engine" on the web server where all the php code is run before sending the web page and any output from the php code down to the browser.

    So depending where your image is coming from, inserting an image in your index.php could be as simple as

    index.php

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
            <title></title>
        </head>
        <body>
            <?php
            
    echo ("Hello");
            
    ?>
            <div>
                <img src="myPic.jpg" alt="myPic" />
            </div>
        </body>
    </html>

  5. #5
    Non-Member
    Join Date
    Oct 2011
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    You can insert image in Index.php file by(<img src="myPic.jpg">) img src command.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •