Get Website Learn Coding Tech Story

PHP Programming Examples

<?php
	$dir = "myDirectory";
	
	/* Checking is directory exist or not */
	if(!is_dir($dir)) {
		
		/* Create directory with full access permission */
		$rs = mkdir($dir,0777) or die("Error...Not able to create directory!");
		if($rs == 1)
			echo "Directory created successfully!";
	}
	else
		echo "Directory already exist!";
	
		
	/* Checking is directory exist or not */
	if(is_dir($dir)) {
		
		/* Delete directory */
		$rs = rmdir($dir) or die("<br />Error...Not able to delete directory!");
		if($rs == 1)
			echo "<br />Directory deleted successfully!";
	}
	else
		echo "<br />Directory not found!";
?> 



          /****** Output ******/
          

Directory created successfully!


Directory deleted successfully!

Learn more about mkdir and rmdir