ritz
ritz

Reputation: 107

In PHP how to create a new directory every time?

I have a Shell script that is calling under a PHP script :-

<?php
shell_exec("sh /home/folder/R.sh /home/folder/input/OM_22_3.txt 
/home/folder/output");

$directoryName = basename(getcwd());
Check if the directory already exists.
if(!is_dir($directoryName)){
Directory does not exist, so lets create it.
mkdir($directoryName, 0755);
}
?>

In this script R.sh is a Shell script, OM_22_3.txt is input file and output is output folder. But this program is not working. I want to make it dynamic like every time when I will run this PHP script it will generate a new output folder for result files. How can I make this dynamic?, What modification is required?

Upvotes: 0

Views: 312

Answers (1)

Aditya Malviya
Aditya Malviya

Reputation: 2150

function CreateDirectory($DirName) {
    if (mkdir($DirName . date(Y-m-d), 0777)) {
        return true;
    } else {
        return false;
    }
}

This will create a directory every day with date, month and year, if you want with time you can append date('h-i-s') also.

Upvotes: 1

Related Questions