WOWDesigns Posted September 20, 2011 Share Posted September 20, 2011 Hi Basically I've built a CMS where by my clients can upload a number of images. On the success page I want to display the images they uploaded by file name. The issue is the number of images can vary. They may upload 2 or 10 or 50 etc. So far I've come up with this: // number of files $UN = 3; //I've set this to 3 for now, but this is passed from the upload page! // server directories and directory names $dir = '../properties'; $images = glob($dir.'/*.{jpg}', GLOB_BRACE); //formats to look for $num_of_files = $UN; //number of images to display from number of uploaded files foreach($images as $image) { $num_of_files--; $newest_mtime = 0; $image = 'BROKEN'; if ($handle = @opendir($dir)) { while (false !== ($file = readdir($handle))) { if (($file != '.') && ($file != '..')) { $mtime = filemtime("$dir/$file"); if ($mtime > $newest_mtime) { $newest_mtime = $mtime; $image = "$file"; } } } } if($num_of_files > -1) //this made me laugh when I wrote it echo $trimmed = ltrim($image, "../properties").'<br />'; //display images else break; } Without this piece of code: $newest_mtime = 0; $image = 'BROKEN'; if ($handle = @opendir($dir)) { while (false !== ($file = readdir($handle))) { if (($file != '.') && ($file != '..')) { $mtime = filemtime("$dir/$file"); if ($mtime > $newest_mtime) { $newest_mtime = $mtime; $image = "$file"; } } } } It shows the first 3 files alphabetically. I want to view the last number of images added. With the above code it simply shows the last image added 3 times! So I need to get the time each image was added and then order by the newest added and limit to the number of images uploaded. Any suggestions please? Kindest regards Glynn Quote Link to comment https://forums.phpfreaks.com/topic/247520-display-last-3-image-files-uploaded-to-a-folder/ Share on other sites More sharing options...
WebStyles Posted September 20, 2011 Share Posted September 20, 2011 On the success page I want to display the images they uploaded by file name hmmm there seems to be some confusion with that question... do you want to show the last 3 of the files they just uploaded, or the last 3 that were uploaded (no matter when) ? Quote Link to comment https://forums.phpfreaks.com/topic/247520-display-last-3-image-files-uploaded-to-a-folder/#findComment-1271059 Share on other sites More sharing options...
WOWDesigns Posted September 20, 2011 Author Share Posted September 20, 2011 Hi, thanks for the reply. To me they are the same thing in essence, but I guess there could be different code that you could use when uploading or simply checking the folder. To be concise, the user chooses how many images they want to upload. On completion they are passed to a success page which will inform them the name of the files uploaded. Previously I just passed the number of files they uploaded and said "You have successfully uploaded X files to the folder foldername". Now I want to be more specific and say "You have successfully uploaded the following files to the folder foldername: *file list*". Kindest regards Glynn Quote Link to comment https://forums.phpfreaks.com/topic/247520-display-last-3-image-files-uploaded-to-a-folder/#findComment-1271117 Share on other sites More sharing options...
WebStyles Posted September 20, 2011 Share Posted September 20, 2011 in that case you don't need to read through the folder contents, you can simply store the file names in a $_SESSION variable when the user uploads and you move them to the final destination, then simply present the user with the file names. Quote Link to comment https://forums.phpfreaks.com/topic/247520-display-last-3-image-files-uploaded-to-a-folder/#findComment-1271159 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.