auto delete

Discussion in 'PHP' started by cavendano, Sep 6, 2007.

  1. #1
    I need a script that will delete files in a specified folder.

    <?php
    
    
    function delfile($str) 
    { 
    foreach(glob($str) as $fn) { 
    unlink("temp/$fn"); 
    } 
    
    
    ?>
    PHP:
    doesnt seem to work...is it possible for the same script to delete files after x days?
     
    cavendano, Sep 6, 2007 IP
  2. jsamdirect

    jsamdirect Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    looks like unlink should work. What happens when you try? Is the script in the same directory as the file?

    Some ref:
    http://us.php.net/delete

    Yes, it is possible to delete a file after xx days. I think the best way would be to write a script that compare todays date to the created or modified date of the file. You could then run this manually or via cron, etc... I am not sure of the exact code, but PHP can handle it.
     
    jsamdirect, Sep 6, 2007 IP
  3. buldozerceto

    buldozerceto Active Member

    Messages:
    1,137
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    88
    #3
    Your script needs to have read and write permissions
     
    buldozerceto, Sep 7, 2007 IP