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 8 of 8
  1. #1
    New Coder
    Join Date
    Jan 2004
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    deletes files from PHP

    PHP Code:
    <?php 
    file1 
    "image.jpg";
    $startdate mktime(0,0,0,12,17,2003); //mktime(hour, minute, second, month, day, year) 
    $datetoday mktime(date("h, i, s, m, d, Y"));//todays date 
    $datediff $datetoday $startdate
    $numdays round($dateDiff/60/60/242); 
    $equalday '$numdays == 7';
    unlink '$file1';
    echo 
    'There is about ' $numdays ' days left to download.<br />';
    echo 
    "Files has removed!";
    ?>
    This scripts will set a time when it will delete the file.
    For example, when it's about 7 days, it will delete the file "$file1", could any one re-write this PHP to makes it works?

    It's like a weekly pictures, by the 7 days it will delete it self and said "times is up"

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try this:

    PHP Code:
    <?php 

    $file1 
    "image.jpg";
    $startdate mktime(0,0,0,12,17,2003); //mktime(hour, minute, second, month, day, year) 
    $datetoday mktime(date("h, i, s, m, d, Y"));//todays date 
    $datediff $datetoday $startdate
    $numdays round($dateDiff/60/60/242); 
    if ( 
    $numdays >= ) {
        
    unlink $file1 );
        echo 
    "File has been removed!";
    } else {
        echo 
    "You have $numdays more days left to download this file.<br />";
    }

    ?>
    I didn't test your date script, I'm just assuming that you calculated it correctly.

  • #3
    New Coder
    Join Date
    Jan 2004
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php 
    $startdate 
    mktime(0,0,0,1,12,2004); //mktime(hour, minute, second, month, day, year) 
    $datetoday mktime(date("h, i, s, m, d, Y"));//todays date 
    $datediff $datetoday $startdate
    $numdays round($datediff/60/60/242); 
    echo 
    ' Nnumbers:' $numdays ' days up.<br />';
    If I use that.. it show .13 days

    but if I use this
    PHP Code:
    <?php 

    $file1 
    "image.jpg";
    $startdate mktime(0,0,0,1,12,2004); //mktime(hour, minute, second, month, day, year) 
    $datetoday mktime(date("h, i, s, m, d, Y"));//todays date 
    $datediff $datetoday $startdate
    $numdays round($dateDiff/60/60/242); 
    if ( 
    $numdays >= 7.00 ) {
        
    unlink $file1 );
        echo 
    "File has been removed!";
    } else {
        echo 
    "You have $numdays more days left to download this file.<br />";
    }
    It shows 0, why is that thought?

    If i change the startdate mktime to like 1/9/2004 still 0 days..

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Tested, works:

    PHP Code:
    <?php 

    $file1 
    "image.jpg";
    $max 7;
    $startdate mktime(0,0,0,1,10,2004); //mktime(hour, minute, second, month, day, year) 
    $datetoday mktime(); //todays date 
    $datediff round(($datetoday-$startdate)/(60*60*24));
    if ( 
    $datediff >= $max ) {
        
    unlink $file1 );
        echo 
    "File has been removed!";
    } else {
        
    $daysleft $max-$datediff;
        echo 
    "You have $daysleft more days left to download this file.<br />";
    }

    ?>

  • #5
    New Coder
    Join Date
    Jan 2004
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you.. i'll try that. and wait to see if it will deleted the file..

  • #6
    New Coder
    Join Date
    Jan 2004
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Warning: unlink(image.jpg): Permission denied in file.php

    Why it can't delete my image.jpg file. even though I set it it file as 777

  • #7
    Regular Coder
    Join Date
    Jan 2004
    Location
    Georgia
    Posts
    306
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Chech and double check your permissions, make sure you have READ/WRITE - READ (rw-r)
    ~Designer's Toolz~

  • #8
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Did you upload that image using php? If you did you might need to chown it so php doesn't 'own' the image.


  •  

    Posting Permissions

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