Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

why I cannot remove directory?

Status
Not open for further replies.

alan123

MIS
Oct 17, 2002
149
0
0
US
I try to delete directory with php code:
Code:
unlink("$dir/.");
rmdir("$dir");

unlink is supposed to delete all files under $dir folder, but it gives me error message "permission denied", actually I created $dir and its files within the same php file:
Code:
mkdir("$dir", 0755);
copy("abc.htm", "$dir/abc.htm");
chmod("$dir/abc.htm",0755);

why I cannot delete files with the same user privilege? can anyone help me? thanks.
 
I don't think that unlink("$dir/."); removes the files. There's no wildcard here. If there are still files then rmdir($dir) will fail.
You need not doublequote the variable if no string parts are added.
 
Thanks for the reply.
So how can I remove all files under $dir folder (even includes .htaccess file)?

 
You will have to delete *.* and .* to cover all the files. .* might give you an error message as the directory entries . and .. cannot be removed.
Another way is to individually delete each file - there are several examples for recursive deletion in the HP manual:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top