Basically when I click my submit button the code should create a random string that is 5 characters in length. Then it should make a folder (relative position) with the name being the random string generated. Then it should create an index file and write the "content" variable to the file. Unfortunately it never even makes the directory. Any help? I can't figure out what's wrong.
<?php
$characters = "abcdefghijklmnopqrstuvwxyz"; // Valid Folder Characters
if(isset($_POST["submit"])) {
$folder = randomString($characters, 5);
$file = fopen($folder . "/index.html", "w");
$content = "File Content";
mkdir($folder, 0777);
fwrite($file, $content);
fclose($file);
}
// Generate Random Folder Name
function randomString($valid_chars, $length) {
$random_string = "";
$num_valid_chars = strlen($valid_chars);
for($i = 0; $i < $length; $i++) {
$random_pick = mt_rand(1, $num_valid_chars);
$random_char = $valid_chars[$random_pick - 1];
$random_string .= $random_char;
}
return $random_string;
}
?>