File Directories PHP Beyond Basics

File Directories PHP Beyond Basics

PHP, TUTORIALS

File Directories PHP Beyond Basics




In this lesson File Directories PHP Beyond Basics we are gonna learn how to work with the directories and folders. We have already know some basic functions about the directories like is_dir() and dirname() etc. This lesson will digging deep into the directories.

Getcwd() – File Directories PHP Beyond Basics

This getcwd() will prints the current working directory of the present file we are working on it. Lets jump into the example and see how to do that.

File Directories PHP Beyond Basics
The above example shows the present working directory, and this is one of the way to get the current Working Directory. And we can dynamically create the directories by using the some default functions. Lets find how to do that.

File Directories PHP Beyond Basics
The above example will creates an new directory called Uploads and you can go and check the present working directory. If you wants to check the user or owner of the file or folder you can do it by go to command prompt or terminal and get the present directory and check its ownership.
We can change the permission by using the umask() function. We can assign the permission by subtract the number from the default value. For example, if we wants to set the 0755 as a permission for a folder or a file then we can subtract 0022 from the default value.
Recursive Directory – File Directories PHP Beyond Basics
The recursive is nothing but create directory inside another directories. Lets see how to do that.




File Directories PHP Beyond Basics
The above is an example for the recursive function. And we can also change the directory from one to another like we did in the following example.
Changing Directory – File Directories PHP Beyond Basics

File Directories PHP Beyond Basics
The above shown is an example for how to change the directory from one to another directory.
Remove Directory – File Directories PHP Beyond Basics
After all we should know how to remove an existing directory. Lets see how to do that.

File Directories PHP Beyond Basics
Things you should remember before you delete a directory are,
1. Make sure the Directory is available or not.
2. Make Sure the directory is Empty or Not
3. Be careful about the contents inside the directory. You can’t revert the data once you remove the directory.
We hope this lesson will taught you some basic functionalities of the directories and folders inside the PHP.
Download the source code for Files Directories PHP Beyond Basics Files Directories.

Leave a Reply