Results 1 to 4 of 4

Thread: Display latest image in directory

  1. #1
    Join Date
    Sep 2013
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Display latest image in directory

    I have images in a directory that are uploaded from smart phones. When uploaded the file name is appended with date & time stamp in Epoch format
    (e.g. image-1392938655.jpg).

    I want to display, on a specific page, only the latest image in that directory.

    Can anyone give me the code I need?

    Thank You

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    1,939
    Thanks
    16
    Thanked 304 Times in 303 Posts
    Blog Entries
    11

    Default

    Focus on Function Web Design | Latest News RSS | Facebook | Twitter |
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps |
    The only limit to creativity is imagination: JemCon.org

  3. The Following User Says Thank You to Beverleyh For This Useful Post:

    pellsonline (03-19-2014)

  4. #3
    Join Date
    Sep 2013
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    I followed link you suggested and found the code to do what I wanted.

    This is what I am using:
    <?php
    $dir = 'fileDir/';
    $base_url = '../demo/uploads/';
    $newest_mtime = 0;
    $show_file = 'BROKEN';
    if ($handle = opendir($dir)) {
    while (false !== ($file = readdir($handle))) {
    if (($file != '.') && ($file != '..')) {
    $mtime = filemtime("$dir/$file");
    if ($mtime > $newest_mtime) {
    $newest_mtime = $mtime;
    $show_file = "$base_url/$file";
    }
    }
    }
    }
    print '<img src="' .$show_file. '" alt="Image Title Here">';
    ?>


    This works fine but displays image in original size.
    I am placing the image into an existing web page and wish to resize it to 250px wide while maintaining height ratio.

    Searched Google but can't find code to insert into the above.

    Any suggestions?
    Thanks

  5. #4
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    1,939
    Thanks
    16
    Thanked 304 Times in 303 Posts
    Blog Entries
    11

    Default

    You can scale the image in HTML - just use the width attribute in the img tag (without a height attribute) http://www.w3schools.com/tags/att_img_width.asp

    However, as this will still force the user to download the full size image, you might want to also look at resizing with something like ImageMagick https://www.google.com/search?q=resi...%20imagemagick or GD Library https://www.google.com/search?q=resi...age%20gd%20php
    Focus on Function Web Design | Latest News RSS | Facebook | Twitter |
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps |
    The only limit to creativity is imagination: JemCon.org

  6. The Following User Says Thank You to Beverleyh For This Useful Post:

    pellsonline (03-27-2014)

Similar Threads

  1. Can't find latest update .js file Image Thumbnail Viewer
    By Ananda in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 02-20-2013, 02:46 PM
  2. Replies: 8
    Last Post: 08-16-2011, 03:40 PM
  3. Directory Display.
    By Jeffreyv1987 in forum PHP
    Replies: 7
    Last Post: 09-08-2009, 11:28 PM
  4. Directory listing display
    By Spacejaguar in forum Other
    Replies: 9
    Last Post: 09-26-2008, 06:25 PM
  5. Looking for script (javascript?) to display page directory
    By mana7 in forum Looking for such a script or service
    Replies: 4
    Last Post: 01-28-2007, 07:40 AM

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
  •