How can directories and index files be automatically generated based on user input in PHP?

To automatically generate directories and index files based on user input in PHP, you can use the mkdir() function to create directories and file_put_contents() function to create index files. You can take user input for directory names and content for index files, and then use these functions to create the directories and index files accordingly.

<?php

// Get user input for directory name and index file content
$directoryName = $_POST['directory_name'];
$indexContent = $_POST['index_content'];

// Create directory
if (!is_dir($directoryName)) {
    mkdir($directoryName);
}

// Create index file inside the directory
$indexFilePath = $directoryName . '/index.php';
file_put_contents($indexFilePath, $indexContent);

?>