On 18 Apr 2009, "Paolo" wrote:
> Hi ar all
>
> in my web site root I have 2 directories:
>
> Firstone is named:pdf
>
> Into the second I have a php file conteining this function:
>
> function CleanFiles($dir)
>
> {
>
> //Delete temporary files
>
> $t = time();
>
> $h = opendir($dir);
Check if the directory stream was actually opened first.
> while($file=readdir($h))
It's a good idea to test if readdir() is not identicle to boolean
false. You might get a filename returned that evaluates to false
in an expression:
while (($file = readdir($h)) !== false)
{
...
>
> {
>
> if(substr($file,0,3)=='tmp' and substr($file,-4)=='.pdf')
It's usually a good idea to use && and || since the precedence of
these is more natural and intuitive in most cases.
> {
>
> $path = $dir.'/'.$file;
You might want to normalize the path data.
> if($t-filemtime($path)>3600)
>
> @unlink($path);
The @ error suppressor is hiding the error that might explain why
you can't delete your files! This is not the right way to handle
it:
/* Check if the file exists */
if (file_exists($path)) {
unlink($path);
}
else {
/* There was an error, maybe log it or display it. */
}
> }
>
> }
>
> closedir($h);
>
> }
>
> When I call this function with CleanFiles("../pdf") it'ld be
> delete all temporany old files
You might echo out the contents of your variable `$path' to see if
the path looks correct to you.
> but it does'nt find old files and it does'nt delete them.
Stop using the @ error suppressor when you need the information the
error can provide to help you.
> Please can you take a look if there are errrors?
>
> Thankyou in advance
Remove the @ error suppressor, and you can find the errors
yourself. There have been several discussions on this recently.
--
~Curtis
$email = str_replace('sig.invalid', 'gmail.com', $from);
Anonymous (1984 IOCCC winner):
int i;main(){for(;i["]<i;++i){--i;}"];read('-'-'-',i+++"hell\
o, world!\n",'/'/'/'));}read(j,i,p){write(j/p+p,i---j,i/i);}
>> Stay informed about: My function not find files to delete