You've already seen how PHP4's FTP functions can help youinteract with files on a remote server. In this article, learn how to usePHP's other file and directory manipulation functions, and build anequivalent application that demonstrates the difference between the twoapproaches.
Next up, a little file and directory manipulation. If you'd like to create directories, PHP provides the mkdir() function, which accepts a file path and a mode as parameters, So, if I wanted to create a directory called "/tmp/me" with permissions 755, I would use something like this:
And to reverse the process, there's always the rmdir()
function, used to delete directories. Note that rmdir() will fail if the directory permissions don't allow deletion, or if the directory contains one or more files.
<?
if (rmdir ("/tmp/me"))
{
echo "Successful!";
}
else
{
echo "Unsuccessful - check permissions and ensure directory is empty!";
}
?>
You can delete files with the unlink() function, which
accepts a filename as parameter. <? if (unlink("/tmp/dummyfile")) { echo "Successful!"; } else { echo "Unsuccessful!"; } ?>
And finally, you can copy files with the copy() function,