hi,

i'm creating some code to upload files, i use $_FILE to get the size...etc :

  $file_type = $_FILES['userfile']['type']; 
  $file_name = $_FILES['userfile']['name'];
  $file_ext = strtolower(substr($file_name,strrpos($file_name,".")));
  $file_size = $_FILES['userfile']['size'];

...but when i realized to get the date i didn't find info... 🙁

My question is, with $_FILES can a get the creation date of the file upload? how can i get that information?

Thanks,
Nelson

    Not too sure about the creation date but you can check the last modified date using the filentime() .

      yep, was just check this one... and i think is the best way...

      thanks Houdini

        5 months later

        I used filemtime() to get the date but I would up with a number like 1164485258. This looks like a gregorian date. Is there a method for converting from gregorian to julian dates?

          darkon_turas wrote:

          I used filemtime() to get the date but I would up with a number like 1164485258. This looks like a gregorian date. Is there a method for converting from gregorian to julian dates?

          [man]filemtime[/man]

          The time is returned as a Unix timestamp, which is suitable for the date() function.

            I don't think the HTTP file upload protocol sends the creation / modified date of the file when it uploads.

            Therefore the timestamp you get from filemtime() is going to be the last modified time of the temporary file it uploads into, which will be recently, hence not useful.

            Mark

              Ok, Then my next question is: How would I go about getting a date stamp and file size from uploaded files?

              I need to have my auto-populated lists display the size and I especially need the date so I cann have it generate a "New" or "Updated" graphic if the matches the current month/year.

              In my case the files already exist. I uploade them via FTP. So far my code looks like this:

              $filename = $row["Filename"];
              $folder = $row["Category"];
              $title = $row["Title"];
              $description = $row["Description"];
              $cover = $row["CoverFilename"];
              $new = $row["New"];
              $filepath = "./download/" . $category . "/" . $filename;
              $file_ext = strtolower(substr($filepath, strrpos($filepath,".")));
              $file_size = $_FILES[$filepath]['size'];
              $date = filemtime($filepath);

              The output gives that number as noted above and the file size is ""

                [man]filemtime[/man]

                See also [man]filectime[/man].

                $filepath = "./download/" . $category . "/" . $filename;
                darkon_turas wrote:

                The output gives that number as noted above and the file size is ""

                You're sure that $filepath refers to a genuine file?

                You'll also want to look at [man]filesize[/man]; it returns the size of a file - $_FILES[$filepath]['size'] doesn't.

                  I didn't know about filesize() existing. That works. The path is valid as that string is also used to make the hyperlink to the files and each hyperlink connects.

                  It appears that the displayed date matches the format output by the strtodate() function and it is different for every file. I can use it to check how old the file is but the PHp server seems to be too old to have the date_format() function. Now I just need to find a way to convert it to the "m/d/Y" format.

                    Who said anything about date_format()? The function that was been referred to was [man]date[/man].

                      I've tried the following and just got errors:

                      $date = date_format($date_file, 'm/d/Y');
                      $date = $date_file->format("m/d/Y");
                      $date = date($date_file, 'm/d/Y');
                      $date = DateTime::timeStampToString($date_file, 'm/d/Y');

                      Note:
                      $date_file is the Linux timestamp of the file
                      $date is the date to be displayed on the web page

                        Never mind, I got it to work be swapping the parameters. I appreciate all the help.

                          Write a Reply...