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

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.