PDA

View Full Version : deletes files from PHP



VietBoyVS
01-12-2004, 04:17 PM
<?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/24, 2);
$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"

x_goose_x
01-12-2004, 09:51 PM
Try this:


<?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/24, 2);
if ( $numdays >= 7 ) {
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.

VietBoyVS
01-12-2004, 11:02 PM
<?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/24, 2);
echo ' Nnumbers:' . $numdays . ' days up.<br />';

If I use that.. it show .13 days

but if I use this


<?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/24, 2);
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..

x_goose_x
01-13-2004, 05:40 AM
Tested, works:


<?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 />";
}

?>

VietBoyVS
01-13-2004, 06:12 AM
thank you.. i'll try that. and wait to see if it will deleted the file..

VietBoyVS
01-13-2004, 11:10 PM
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

DsgnrsTLZAdmin
01-14-2004, 11:11 PM
Chech and double check your permissions, make sure you have READ/WRITE - READ (rw-r)

Nightfire
01-14-2004, 11:49 PM
Did you upload that image using php? If you did you might need to chown it so php doesn't 'own' the image.