Howdy... 🙂

I am trying to create a script which does following...

A user clicks on the form and selects the file to upload...
The script displays the uploaded file on the screen as soon as upload completes...

Simple enough, I guess...
That part is pretty much done and works properly...

Now, I need to add a cleanup routine... If 10 person uploads their files, I'll end up with 10 additional files and it could be 100s files in a matter of a day or two... and we don't want that...

Luckily, the files that are uploaded can be deleted as soon as the user's browser gets closed... That sounds like a good place to clean up that uploaded file, but I am sorta lost on that part...

So, I was thinking maybe I should really check if there is one day old file in the given directory and delete them if there are before I even open up the upload form... and I am pretty much lost on that part as well...

Can anybody give me some suggestion on this???

Thanks... 🙂

Jason

    Thanks, Weedpacket... 🙂

    I was playing with fileatime and filemtime last night to see if any of those will work for me, but both gave me current date, so I just left the last one I tried, fileatime and went to sleep...

    I just got up and tried both again and filemtime works... Lovely... 🙂

    While we are in the subject, I'd like to ask one more question... 🙂

    I have two date formats...

    $now = date("Ymd His");
    $mTime = date("Ymd His", filemtime($f));
    $diff = $now - $mTime;
    echo($now . " : " . $mTime . " : " . $diff);

    and here is some test result for the files...

    20050926 063408 : 20050120 163922 : 806
    20050926 063408 : 20050120 164013 : 806
    20050926 063408 : 20050925 195317 : 1
    20050926 063408 : 20050925 212655 : 1
    20050926 063408 : 20050925 195338 : 1
    20050926 063408 : 20050925 205533 : 1
    20050926 063408 : 20050925 205547 : 1

    Can you tell me what that $diff is supposed to be??? I am trying to get $diff in date format, but it looks like PHP is doing minus with the integer values...

    Ultimately, I am wanting to get to use $diff to see if the $mTime is one hour old or not so that I can delete the file that is more than one hour old...

    Thanks... 🙂

      Working now? Probably 'cos it's a day later 🙂

      Nothing meaningful. It's 20050926-20050120. Numbers don't have spaces, so when the strings you're making are converted to numbers for the subtraction, everything from the space on is dropped. And of course there's not a lot of point trying to subtract 20050120 from 20050926 unless months each had 100 days in them. Also, "getting the diff in date format" doesn't really make much sense either - what's October minus June?
      Just stick with Unix timestamps.

      $now=time();
      $then=filemtime($f);
      $diff = $now-$then; // difference between current time and modification time, in seconds
      
        Weedpacket wrote:

        Working now? Probably 'cos it's a day later 🙂

        Exactly... 😃

        Nothing meaningful. It's 20050926-20050120. Numbers don't have spaces, so when the strings you're making are converted to numbers for the subtraction, everything from the space on is dropped. And of course there's not a lot of point trying to subtract 20050120 from 20050926 unless months each had 100 days in them. Also, "getting the diff in date format" doesn't really make much sense either - what's October minus June?

        Yup... That makes total sense... Thanks for the explanation... 🙂

        Just stick with Unix timestamps.

        $now=time();
        $then=filemtime($f);
        $diff = $now-$then; // difference between current time and modification time, in seconds
        

        Cool... That works beautifully... 😉

          Write a Reply...