Jump to content

PHP Form and Images?


cjenkins08

Recommended Posts

I'm pretty new to PHP, but I am wondering what would be the easiest way to accomplish this.

 

I am looking to have a form with two different lists(each list will have the name of one of the 50 states), the user will be able to select one state from each list.

 

Each state on the list will have a picture of the state that is accociated with it.

What is the easiest way to connect the name chosen with the image associated with it?

 

Should this be in a Database?

Should the images be stored direct or via a link to the URL of the images?

Could the images just be stored in an Array?

 

Using FPDF I have already styled a page, then I am then going to display the two state images in that same .pdf file.

Link to comment
https://forums.phpfreaks.com/topic/288063-php-form-and-images/
Share on other sites

 

 

What is the easiest way to connect the name chosen with the image associated with it?

Give each image the name of the state. eg Alabama.png,  Ohio.png etc.

 

You'd set up your dropdown menu like

State:
<select name="state">
   <option>Alabama</option>
   <option>Alaska</option>
   <option>Arizona</option>
   ...
   <option>Wyoming</option>
</option>

You'd then link to the image using something like this

if(isset($_POST['state']))
{
    // load the state images stored in site.com/images/states into an array
    $state_images = glob('images/states/*.png');
    
    // get the associated image
    if(in_array($_POST['state'] . '.png', $state_images))
    {
        $state_image_path = '/images/states/'.$_POST['state'].'.png';
    }

    // display the associated image
    echo 'State Selected: ' . $_POST['state'] . '<br />State Image: <img src="'.$state_image_path.'" />';
}
Link to comment
https://forums.phpfreaks.com/topic/288063-php-form-and-images/#findComment-1477454
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.