Create directories with PHP

I take a lot of pictures and pretty much take a picture every day. I keep them categorized by year and month. So each each month I end of making at least one folder for each day. Well, why not just create a PHP script to do this for me. So I did.

The following script does a few things.

First, it creates the HTML <option> form elements . I created a function that creates an array with all of the months listed. Each month has a corresponding index (1-12).

I also set a variable for “selected”, which will be added to the option element for the current month. Usually I make these folders soon after the first of the month, so the selected month will always be the current month. I will be able to of course choose any month from the selection list.

I also set a variable to hold the index. This will be using as the script loops through the array of months and will add the “selected” attribute when the index and current month are the same.

That same loop is creating the “select” list and each option for each month in the year. Again, this is done by looping through the array that holds all 12 months.

The folders are created when the form with the section list is submitted. A “while” loop creates a folder for each day of the month.

function Options()
    $current_month = date("m");
    $month[1] = "Jan";
    $month[2] = "Feb";
    $month[3] = "March";
    $month[4] = "April";
    $month[5] = "May";
    $month[6] = "June";
    $month[7] = "July";
    $month[8] = "Aug";
    $month[9] = "Sept";
    $month[10] = "Oct";
    $month[11] = "Nov";
    $month[12] = "Dec";
    $selected = 'selected';
    $index = 0;

    echo '<select id="month" name="month">';
    foreach ($month as $value)
        $index = ++$index;
        if($current_month == $index){$selected = 'selected';}else{$selected = '';}
         echo '<option value="'.$index.'" '.$selected.'>'.$value.'</option>';
    echo '</select>';
$current_year = date("Y");
$current_month = date("m");

    $x = 1;
    $selected_month = $_POST['month'];
    $Num_days_current_month = cal_days_in_month(CAL_GREGORIAN,$selected_month,$current_year);
    while($x <= $Num_days_current_month)

Thank you for reading!

It's only fair to share...Tweet about this on Twitter
Share on Facebook
Email this to someone