What does it mean?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rainbow
Forum Newbie
Posts: 13
Joined: Thu Aug 22, 2002 6:03 am
Location: Finland

What does it mean?

Post by rainbow »

I'm working on a script which has been developed by another person. It deals with folder removing. Here is the part of code:

Code: Select all

if ($dir = @opendir("$dir2remove"))
{
    while (($file = readdir($dir)) !== false)
    {
          if (!($file=="." || $file==".." || $file=="index.html"))
          {
            chdir($version_depository."topic".$ct_topic_id."/".$file);
            system("rm *");

            chdir($version_depository."topic".$ct_topic_id."/");
            rmdir($file);
          }
    } //close while
    closedir($dir);
But i don't understand well the following line:
"system("rm *");" Does it mean to delete the folder? But the command for deleting folder is another. Ijust couldn't find anyting similiar in php manual. So can anyone help me?
"
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

system("rm *"); is similar to opening a new shell (or cmd/command.exe on win32) and execute the given command.
so 'rm *' will remove all files in the current directory on unix.
It does not recurse in sub directories ( rm -R * dos/win: del *.* , del /S *.* )

The script is dangerous in at least two ways:
- it doesn't check if chdir worked properly (bye bye script dir ;) )
- on some systems rm * is 'protected' by a confirmation question (are you sure? y/n)
rainbow
Forum Newbie
Posts: 13
Joined: Thu Aug 22, 2002 6:03 am
Location: Finland

Post by rainbow »

Thanks a lot ! :)
Post Reply