Jam-ez
27-05-2009, 09:50 AM
Hello all,
I'm currently working on a private "uploader" type script. As I'm a lazy idiot, I'm working on an admin page that'll allow me to either:
- delete the directory and remake it with the appropriate permissions.
- delete all files in the directory, but leave the directory outstanding.
Deleting the directory is easy, with a function such as:
(not created by me:)
function rmdirr($dirname)
{
// Sanity check
if (!file_exists($dirname)) {
return false;
}
// Simple delete for a file
if (is_file($dirname) || is_link($dirname)) {
return unlink($dirname);
}
// Loop through the folder
$dir = dir($dirname);
while (false !== $entry = $dir->read()) {
// Skip pointers
if ($entry == '.' || $entry == '..') {
continue;
}
// Recurse
rmdirr($dirname . DIRECTORY_SEPARATOR . $entry);
}
// Clean up
$dir->close();
return rmdir($dirname);
}
Then executing it, with a:
mkdir( $directory );
However, is it possible to chmod that by connecting to ftp? I checked out some links and php.net, but would it just be easier to attempt to delete every file in the directory?
Thanks a lot!
I'm currently working on a private "uploader" type script. As I'm a lazy idiot, I'm working on an admin page that'll allow me to either:
- delete the directory and remake it with the appropriate permissions.
- delete all files in the directory, but leave the directory outstanding.
Deleting the directory is easy, with a function such as:
(not created by me:)
function rmdirr($dirname)
{
// Sanity check
if (!file_exists($dirname)) {
return false;
}
// Simple delete for a file
if (is_file($dirname) || is_link($dirname)) {
return unlink($dirname);
}
// Loop through the folder
$dir = dir($dirname);
while (false !== $entry = $dir->read()) {
// Skip pointers
if ($entry == '.' || $entry == '..') {
continue;
}
// Recurse
rmdirr($dirname . DIRECTORY_SEPARATOR . $entry);
}
// Clean up
$dir->close();
return rmdir($dirname);
}
Then executing it, with a:
mkdir( $directory );
However, is it possible to chmod that by connecting to ftp? I checked out some links and php.net, but would it just be easier to attempt to delete every file in the directory?
Thanks a lot!