php
Check if a folder already created using PHP
You can use this code to check whether a folder or directory already exists or not. We are using a PHP script to check that.
<?php
$newdirname = $_POST["new_dir_name"];
$dir_path = "path/to/" . $newdirname . "/";
if (!file_exists($dir_path)) {
mkdir($dir_path, 0777);
echo "The directory creted successfully.";
exit;
} else {
echo "The directory already exists.";
}
?>
Was this helpful?
Similar Posts
- Check if item exist in array using PHP
- Check if value exist in array using in_array() PHP
- Check if string contains a substring using PHP
- Check empty string in PHP
- Check if file exist in PHP
- Send POST request without using curl using PHP 5+
- Convert characters to lowercase using strtolower() function in PHP