How can PHP scripts generate random folder names for file uploads?
To generate random folder names for file uploads in PHP, you can use the `uniqid()` function along with `md5()` or `sha1()` to create a unique folder name. This ensures that each folder name is unique and not easily guessable. You can then use this random folder name to store the uploaded files securely.
// Generate a random folder name for file uploads
$folderName = uniqid(md5(rand()), true);
// Create the folder if it doesn't exist
if (!file_exists($folderName)) {
mkdir($folderName, 0777, true);
}
// Move the uploaded file to the random folder
move_uploaded_file($_FILES["file"]["tmp_name"], $folderName . "/" . $_FILES["file"]["name"]);
echo "File uploaded to folder: " . $folderName;