php

Create folder inside folder in PHP

Spread the love

Let us tell you how to create folder inside folder in PHP.

For example if today’s date is 13-11-2020 then first a folder named 2020 will be created and inside it a folder named 11 will be created and then a folder named 13 will be created.

<?php
	$year_dir_name = date('Y'); // current year
	$month_dir_name = date('m');  // current month
	$date_dir_name = date('d'); // current day	

	$root_path = "upload/";	// root path

	$year_dir_path = $root_path.$year_dir_name."/";
	$month_dir_path = $year_dir_path."/".$month_dir_name."/";	
	
	if (!is_dir($root_path.$year_dir_name)) {
		mkdir($root_path.$year_dir_name, 0777, TRUE);
		chmod($root_path.$year_dir_name, 0777);
	}
	if (!is_dir($year_dir_path.$month_dir_name)) {
		mkdir($year_dir_path.$month_dir_name, 0777, TRUE);
		chmod($year_dir_path.$month_dir_name, 0777);
	}
	if (!is_dir($month_dir_path.$date_dir_name)) {
		mkdir($month_dir_path.$date_dir_name, 0777, TRUE);
		chmod($month_dir_path.$date_dir_name, 0777);
	}
?>
  • Output –
Create folder inside folder in php

Create folder inside folder in PHP

Leave a Reply

Your email address will not be published. Required fields are marked *