Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2012
    Thanked 0 Times in 0 Posts

    Exclamation Displaying most recent image from folder into div using PHP


    I am working on a website that would allow the customers to customize their t-shirts by uploading their own image, place and resize it on the t-shirt. I have come across an issue though. After uploading the image into the 'uploads/' folder, it will not show up in the div for the customer to move and resize it.

    Here is the code that I am using:

    $dir = 'uploads/';
    $base_url = 'http://www.myurl.com/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">';
    I guess I don't know how to tell the code in the div to show the file? Could anyone help? I am ready to rip my hair out.

    Thank you in advance

  2. #2
    Senior Coder
    Join Date
    Sep 2010
    Thanked 275 Times in 275 Posts
    This line:
    $show_file = "$base_url/$file";
    should be:
    $show_file = $base_url."/".$file;

    There may be other errors.


Posting Permissions

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