Possible Duplicate:
PHP uploading script - create folder automatically
I have a PHP Script that creates a folder based on a form. I'm wondering if there is a way to NOt create and replace that folder if it already exists?
<?php
mkdir("QuickLinks/$_POST[contractno]");
?>
You can use is_dir:
<?php
$path = "QuickLinks/$_POST[contractno]";
if(!is_dir($path)){
mkdir($path);
}
?>
In general:
$dirname = "whatever";
if (!is_dir($dirname)) {
mkdir($dirname);
}
In particular: be very careful when doing filesystem (or any other type of sensitive) operations that involve user input! The current example (create a directory) doesn't leave much of an open attack surface, but validating the input can never hurt.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With