Reputation: 2693
I would like to delete all images from a folder called tempimages that are older than 1 hour. I found the example below on Stack Overflow but I'm getting a parse error:
syntax error, unexpected '{' in /delete-old-images.php on line 13
<?php
function destroy($dir) {
$mydir = opendir($dir);
while($file = readdir($mydir)) {
if($file != "." && $file != "..") {
chmod($dir.$file, 0777);
if(is_dir($dir.$file)) {
chdir('.');
while($dir.$file) {
if(date("U",filectime($file) >= time() - 3600)
{
unlink($dir.$file)
}
}
}
else
unlink($dir.$file) or DIE("couldn't delete $dir$file<br />");
}
}
closedir($mydir);
}
destroy("tempimages/");
?>
My server data:
PHP Version 5.3.18-nmm1
System Linux #116-Ubuntu SMP Tue Nov 12 19:37:57 UTC 2013 x86_64
Build Date Oct 26 2012 16:30:11
Server API Apache 2.0 Handler
How to fix it?
Upvotes: 1
Views: 947
Reputation: 406
You haven't close the bracket for if condition.
if(date("U",filectime($file) >= time() - 3600)
Should be
if(date("U",filectime($file) >= time() - 3600))
and missed the semicolumn
unlink($dir.$file)
Should be
unlink($dir.$file);
Upvotes: 0
Reputation: 68486
You forgot to close the date()
if(date("U",filectime($file)) >= time() - 3600)
-------^
and missed a semi colon here
unlink($dir.$file);
-----^
Upvotes: 2