PHP Directory - php ajax - Phptpoint.com

PHP Directory

Best PHP Training with Live Project in Noida Fee is only 7500/-Click here for FREE DEMO.

/ins>

Work With Directory PHP

Directory is the collection of related files.

How to create a directory using PHP

Syntax

Eg

In the above example
in this program we use mkdir()function . Pass the directory name inside this function to create the directory.


Create a sub directory inside existing directory

Syntax

Eg

In the above example use mkdir( ) function . pass the directory name/sub directory name inside mkdir() function sub directory create inside the main directory(make sure first must create a directory).


How to remove(delete) a directory in PHP

Syntax

Eg

In the above example
We want to delete existing directory. Pass directory name “mydocs” inside rmdir( ) function.
it will delete the directory.


How to rename a directory

Syntax

Eg

In the above example
if we want to rename a directory name. rename( ) function is used. it accept two argument first “the existing directory name” and second “new name which replace first directory name”.

How to check existence of directory

Syntax

Eg

In the above example
if we want to check the existence of a directory. file_exist( ) function is used with (directory name) .
if directory exist it gives true(“1”)


How to get files(contents) from directory

Note first manually store some files inside your directory
Syntax

Eg

in the above example
We get the contents of a directory. use scandir( ) function , directory name declare inside this.
scandir( ) function returns the files in array so stored the return value in a variable( $files).

Now print this using print_r($files) function i.e specially used to print the value and index of array.
it gives an output of an array type with index and their corresponding value.


How to open a directory

Syntax

Eg

In the above example
if we open the directory use opendir( ) function with directory name (“mydocs”).
store in variable $files because these open directory variable is going to used in further communication(for reading the contents).


How to read all files from a directory

Syntax

Eg

In the above example
first we open the directory of name(“mydocs”) and stores the values in $files(in previous example).
Now start to read the file using readdir( ) function till the file ends because here we are using while( ) loop. To display the file name we have used echo statement in while loop.

Keep Updating yourself