Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

My function not find files to delete

 
   Database Help (Home) -> PHP RSS
Next:  Instant Web Publishing on server 8.0  
Author Message
Paolo

External


Since: Dec 18, 2008
Posts: 2



(Msg. 1) Posted: Sat Apr 18, 2009 10:25 am
Post subject: My function not find files to delete
Archived from groups: comp>lang>php (more info?)

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);

while($file=readdir($h))

{

if(substr($file,0,3)=='tmp' and substr($file,-4)=='.pdf')

{

$path = $dir.'/'.$file;

if($t-filemtime($path)>3600)

@unlink($path);

}

}

closedir($h);

}

When I call this function with CleanFiles("../pdf") it'ld be delete all
temporany old files

but it does'nt find old files and it does'nt delete them.

Please can you take a look if there are errrors?

Thankyou in advance

 >> Stay informed about: My function not find files to delete 
Back to top
Login to vote
Curtis Dyer

External


Since: Feb 24, 2009
Posts: 2



(Msg. 2) Posted: Sun Apr 19, 2009 12:25 am
Post subject: Re: My function not find files to delete [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
How to delete all files beginning with ... ? - Hi, I'm using PHP 4. I would like to delete all files in my directory /mydir that match the regular expression /mydir/temp* What is the shortest way in which I can do this? Thanks, - Dave

Delete a directory and all its files and sub-directories? - Hi, Does anyone know of, or have code that will delete a php directory and all its sub directories and files. "unlink" and "rmdir" don't do this. I'd prefer not to use "exec" with a system call but if that's the only way,...

Find urls in plain text files - What is the best regular expression for finding urls in plain text files? (By urls I mean http://www.something.com, but also www.something.com, or salve@somewhere.com) Salve

How to find what called a function - I am making a logger class in my application, i want to put a display the source which called the logging method. How can i do this? say if i call Logger->debug("Test Message") then the Logger can display DEBUG:SOURCE of CALL:Test Message

Some php files in same directory of working files with sam.. -
   Database Help (Home) -> PHP All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]