Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Nov 2007
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Can I pass IMG attributes to a PHP page?

    Hi Folks,

    I have a webpage that has some photos on it. They are displayed smaller than full size on most of the pages. I would like to make the images clickable to view them full size but not on a white page. I want them to be put into the same php generated pages the rest of the content uses.

    I have had success doing this, but for each photo I put a static link that passes the information to the php file. For example:

    Code:
    <a href="picview.php?fname=images/myphoto.jpg&amp;caption=My Caption For This Picture">
      <img src="images/myphoto.jpg" alt="a picture" title="My Caption For This Picture" />
    </a>
    Then on the php page side I use:
    Code:
    <img src="<?php echo $_GET['fname']; ?>" alt="Larger Image" />
    <p><?php echo $_GET['caption']; ?></p>
    Is there a more automatic way that will allow me to pull the filename and the title out of the <img></img> on the originating page and send it to the destination page?

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Not with PHP, but you should be able to with Javascript.

  • #3
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,509
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    You can create a simple text file that has a list of your photos.
    The first field is a timestamp (or ID).

    Something like this ... (call it "photos.db" )
    Code:
    1001|myphoto1.jpg|myphoto1_t.jpg|This is photo one's title|extra fields|
    1002|myphoto2.jpg|myphoto2_t.jpg|This is photo two title|extra fields|
    1003|myphoto3.jpg|myphoto3_t.jpg|This is photo three title|extra fields|
    1004|myphoto4.jpg|myphoto4_t.jpg|This is photo four title|extra fields|
    1005|myphoto5.jpg|myphoto5_t.jpg|This is photo five title|extra fields|
    Then, your link is like this ... All of your thumbs could actually
    be created by a PHP script that opens the text database and
    creates the links/thumbs for you. But this is what 1 link looks like ...

    <a href="picview.php?id=1001">
    <img src="images/myphoto.jpg" />
    </a>

    Your PHP script is like this ("picview.php" ... simple example.)
    PHP Code:
    <?php
    $id
    =$_GET['id'];
    #Read File List
    $database="photos.db";
    $fp fopen($database"r");
    $array1 explode("\n"fread($fpfilesize($database))); 
    fclose ($fp);
    ?>
    <html>
    <head><title>Page Title</title>
    <style>
    /* All of your CSS style stuff here */
    body {
    margin:0px auto;
    }
    </style>
    </head>
    <body>

    <?php
    $count 
    count($array1);
    for(
    $i 1$i $count$i++) {
    list (
    $fid$full$thumb$title$extra) = split ('\|'$array1[$i]);
    if(
    $id == $fid){
    // display full size image
    echo"
    <img src='$full' alt='$title' />
    "
    ;
    }
    }
    ?>

    </body>
    </html>

  • Users who have thanked mlseim for this post:

    barney_1 (11-24-2007)

  • #4
    New Coder
    Join Date
    Nov 2007
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Wow, thanks! I had thought of doing it that way but dismissed it as too convoluted. It'll take me some time to sift through the code so I understand it, but I do appreciate you posting it.


  •  

    Posting Permissions

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