Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4

Thread: Image handling.

  1. #1
    Senior Member simpleurl's Avatar
    Join Date
    Jul 2006
    Location
    Leicester, UK.
    Posts
    150
    Member #
    13598
    I am having trouble at the minute with a photo album. Is there anyway that I can use PHP to find images in a folder and echo the image name with a certain bit of code?

    e.g.
    when the images have been found echo
    Code:
    <a href="gallery/Paul and Chris.JPG" rel="lightbox[gallery]" title="This is our caption">
    <img height="100%" width="130px" src="gallery/Paul and Chris.JPG" border="0" />
    I would like to do this because i have quite a lot of images and dont want to do all that code, like changing names and creating new links.

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,715
    Member #
    5580
    Liked
    717 times
    You could do something simple like this:

    1) Create a text file with all of your entries (name the file "photos.txt")

    1001|paul_and_chris.jpg|400|600|Paul and Chris|Some other stuff|
    1002|my_house.jpg|420|640|My new house|Some other stuff|
    1003|another_photo.jpg|410|610|Another Photo|Some other stuff|

    2) Then a PHP script to open the text file, read the entries, and
    sort by entry number, then display them in a loop.

    <?php
    #Read your text file
    $filename="photos.txt";
    $lines = array();
    $fp = fopen($filename, "r");
    $array1 = explode("\n", fread($fp, filesize($filename)));
    fclose ($fp);
    sort($array1);# rsort=reverse sort

    $count_array=count($array1);
    for ($i=0;$i<$count_array;$i++) {
    list ($id, $photo, $width, $height, $caption, $other) = split ('\|', $array1[$i]);
    echo"<a href='gallery/$photo' rel='lightbox[gallery]' title='$caption'><img height='$height' width='$width' src='$photo' border='0' />";
    }
    ?>


  4. #3
    Senior Member simpleurl's Avatar
    Join Date
    Jul 2006
    Location
    Leicester, UK.
    Posts
    150
    Member #
    13598
    Thanks a lot for that.

  5. #4
    Senior Member hagen's Avatar
    Join Date
    Aug 2005
    Posts
    408
    Member #
    10882
    Liked
    1 times
    Hagen Rose: hagen(at)jxwd(dot)co(dot)uk
    JX Web Development, Bournemouth, Dorset...JXWD.co.uk


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:26 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com