Jump to content

List files in a directory and grab the first filename


bsamson

Recommended Posts

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!!

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.