Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8858757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:54:02+00:00 2026-06-14T14:54:02+00:00

I have a webpage that I want to dynamically display content depending on the

  • 0

I have a webpage that I want to dynamically display content depending on the path of the page. For example, I may want http://www.page.php?input=red or maybe I’ll want http://www.page.php?input=blue. In both cases, the actual content is located in ./$dir/.

I’ve got the gist of this down, but I can’t for the life of me figure out images. I have an image in each directory at ./$dir/subdir/images/sample.png. How do I output HTML that dynamically alters the image element?

Here is sample code to demonstrate my question.

<html>
    <?php
        $dir = $_GET["input"];
        $img = imagecreatefrompng("./$dir/subdir/images/sample.png");
    ?>
    <body>
        <img src="???" alt="sample image" />
    </body>
</html>

I want to display ./red/subdir/images/sample.png when I have input=red, ./blue/subdir/images/sample.png when input=blue, etc.

Many thanks in advance for any help.

Edit:
I don’t even know if I can store an image into a variable as seen on line 4. I’m really new to PHP.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:54:03+00:00Added an answer on June 14, 2026 at 2:54 pm

    If only one image:

    <img src="<?= $img ?>" alt="sample image" />
    

    If loads of images, use an array.

    I would also set the alt text on a database, pull it from there and write it the same way I suggested writing the src.

    Just so you can understand:

    <?= $img ?>
    

    Does exactly the same thing as

    <?php echo $img; ?>
    

    Except with a bit more class.

    edit: Typo on the indent made my code disappear.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a webpage that redirects to another webpage like this: http://www.myOtherServer.com/Sponsor.php?RedirectPage=http://mylink.com/whereIwasgoingtogo.html Then the
I have a string that I want to display on a web page that
i have a webpage that looks like this: http://yoursdproperty.com/index2.php?option=com_jumi&fileid=3&Itemid=11 i want the page to
i have a web page that i want to load dynamically (ajax) into a
I have a dynamically created TextBox in a C#/ASP.NET web page that I want
I have a webpage that displays a calendar, and I want to change the
I have a number of outgoing links on my webpage that I want to
I have a webpage that retrieves data (via ajax/php) and shows it in an
I have a webpage that is only accessible over http basic auth. How can
I have a webpage that dynamically prepends new divs about once per minute. Here

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.