Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Oct 2005
    Posts
    61
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Lightbulb reading time from a file

    Hello,

    How can i read the time from a file uploaded/created?
    i like to include a new hidden field to store into mysql along with the file detail, so later i can sort thru time.

    thank you for your time n help in advance

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,899
    Thanks
    15
    Thanked 226 Times in 226 Posts
    Is the time already written to the file, and if so, in what format? Or do you have to devise a way to write the time to the file too, and also in what format? As for doing what you asked, you fopen the file, place the file pointer at the proper line in the file, and read that line. But if you want more information you'll have to supply more too.

  • #3
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    the time you uploaded it or the time the file was originally created on the client ? , if the latter you cant get that.
    if the time you uploaded simply add a time field in your database table you can use mysql NOW() function to add the time of the operation

    `db_field` = NOW()
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #4
    New Coder
    Join Date
    Oct 2005
    Posts
    61
    Thanks
    12
    Thanked 0 Times in 0 Posts
    thank you both

    currently i have a column in a table to show all the uploaded files.
    what i need help is to have some php code line, which will loop or display each file's last modified time or server uploaded time.. that way, at the end, i will have 2 columsn to show the filename and date/time to sort.

    thank you

  • #5
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    You could try these, they are untested and I don't know what sort of info they will display.


    PHP Code:
    <?php
    // get file access/modification times
    echo "Last accessed on: " date("d-m-y"fileatime('myfile.html'));
     
    echo 
    "Last modified on: " date("d-m-y"filemtime('myfile.html'));
    ?>
    PHP Code:
    <?php
    // get file statistics
    print_r(stat('myfile.html'));
    ?>
    The uploaded time is easy and would be coded into the upload form to be entered into the database automatically.
    Last edited by Len Whistler; 07-15-2012 at 04:00 AM.
    Leonard Whistler

  • Users who have thanked Len Whistler for this post:

    pagedrop (07-15-2012)

  • #6
    New Coder
    Join Date
    Oct 2005
    Posts
    61
    Thanks
    12
    Thanked 0 Times in 0 Posts
    thank you Len

    it helped me, got it to work manually, when i list the filename..
    i currently use this line to pull up the filename uploaded with its href
    PHP Code:
    echo "<a href=\"users""/" $username $viewurl "/" $filearray[$index] . "\">" $filearray[$index] . "</a> "
    I tried implementing in your code, but i keep getting errors with "" syntax error, unexpected T_STRING etc.

    Could you please let me know how to implement it correctly
    Note: from the code line i posted above, it shows the filename AND its fullpath. but in this case, we only need the fullpath for filemtime or fileatime.

    thank you


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •