PDA

View Full Version : [PHP] - Directory's and their files



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!

Blob
27-05-2009, 11:34 AM
http://uk.php.net/chmod

?

Jam-ez
27-05-2009, 11:55 AM
http://uk.php.net/chmod

?

Aye, but is it easier to just delete all the files in the directory?

Blob
27-05-2009, 11:56 AM
Not really, it only takes one line to do it.

Jam-ez
27-05-2009, 12:08 PM
Not really, it only takes one line to do it.

Aright, thanks a bunch.

Want to hide these adverts? Register an account for free!