bsamson Posted August 10, 2010 Share Posted August 10, 2010 Hello. I have a directory with files that look like this: priceguide_20100809.pdf priceguide_20100808.pdf priceguide_20100807.pdf priceguide_20100806.pdf I am trying to come up with a function that will grab and save the filename with the biggest date .. ie: priceguide_20100809.pdf. Any assistance would be greatly appreciated!! Link to comment https://forums.phpfreaks.com/topic/210345-list-files-in-a-directory-and-grab-the-first-filename/ Share on other sites More sharing options...
bsamson Posted August 10, 2010 Author Share Posted August 10, 2010 Found this great code that lists the file by timestamp ... exactly what I needed. Hope this helps someone else. define ("FILEREPOSITORY", "/home/nxsap/public_html/uploads/"); if (is_uploaded_file($_FILES['priceguide']['tmp_name'])) { if ($_FILES['priceguide']['type'] != "application/pdf") { echo "<p>Class notes must be uploaded in PDF format.</p>"; } else { $name = "priceguide"; $result = move_uploaded_file($_FILES['priceguide']['tmp_name'], FILEREPOSITORY."$name.pdf"); if ($result == 1) echo "<p>File successfully uploaded.</p>"; else echo "<p>There was a problem uploading the file.</p>"; } #endIF } #endIF Link to comment https://forums.phpfreaks.com/topic/210345-list-files-in-a-directory-and-grab-the-first-filename/#findComment-1097683 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.