function traverseStructure($iterator)
{
    global $cur_path;
    while ($iterator->valid()) {
        if ($iterator->hasChildren()) {
            if ($iterator->key()) {
                if ($iterator->key() !== 'fileStruct') {
                    $check_key = checkEntry($iterator->key());
                    if ($check_key) {
                        if ($check_key[0] == 'd') {
                            if (file_exists(getcwd() . "\\" . $check_key[1] . "\\")) {
                                echo 'Folder "' . $check_key[1] . '" already exists, skipping.<br>';
                                $cur_path = getcwd() . "\\" . $check_key[1] . "\\";
                            } else {
                                mkdir(getcwd() . "\\" . $check_key[1] . "\\");
                                echo 'Folder "' . $check_key[1] . '" created.<br>';
                                $cur_path = getcwd() . "\\" . $check_key[1] . "\\";
                            }
                        }
                    }
                }
            }
            traverseStructure($iterator->getChildren());
        } else {
            $check_cur = checkEntry($iterator->current());
            if ($check_cur) {
                if ($check_cur[0] == 'f') {
                    if (!file_exists($cur_path . $check_cur[1])) {
                        fopen($cur_path . $check_cur[1], 'w');
                        echo 'File "' . $check_cur[1] . '" created.<BR>';
                    } else {
                        echo 'File "' . $check_cur[1] . '"already exists, skipping.<BR>';
                    }
                }
                if ($check_cur[0] == 'd') {
                    if (file_exists(getcwd() . "\\" . $check_cur[1] . "\\")) {
                        echo 'Folder "' . $check_cur[1] . '" already exists, skipping.<br>';
                    } else {
                        mkdir(getcwd() . "\\" . $check_cur[1] . "\\");
                        echo 'Folder "' . $check_cur[1] . '" created.<br>';
                    }
                }
            }
        }
        $iterator->next();
    }
}
Example #2
0
<!DOCTYPE html>
<html>
	<head>
		<title>Fruit Store</title>
		<link href="http://selab.hanyang.ac.kr/courses/cse326/2015/problems/pResources/gradestore.css" type="text/css" rel="stylesheet" />
	</head>

	<body>
		
		<?php 
# Ex 4 :
# Check the existance of each parameter using the PHP function 'isset'.
# Check the blankness of an element in $_POST by comparing it to the empty string.
# (can also use the element itself as a Boolean test!)
if (!checkEntry()) {
    ?>

		<!-- Ex 4 : 
			Display the below error message : --> 
			<h1>Sorry</h1>
			<p>You didn't fill out the form completely. Try again?</p>
		

		<?php 
    # Ex 5 :
    # Check if the name is composed of alphabets, dash(-), ora single white space.
    #} elseif (checkName()) {
    ?>

		<!-- Ex 5 : 
			Display the below error message :