What's new
  • Welcome to PHCorner Forums. Take a moment to Sign up and gain unlimited access and extra privileges that guests are not entitled to, such as: All that and more! Registration is quick, simple and absolutely free. Join our community today!

Help Sino magaling sa ganito na naka array looping sa codeigniter pa helped sa mga naka experience na parang pyramid na may under na subfolder

ThePoyPi

Journeyman
, Last edited:
wait try ko :)

Code:
<?php
/* Folder Name */
$buyer_name = "buyer_name";

/* Directory Structure */
$directory_tree = array(
    [
        'dir_name' => 'CNC',
        'sub_folder' => [
            [
                'dir_name' => 'FILES',
                'sub_folder' => [
                    ['dir_name' => 'SUBMITTED REQUIREMENTS'],
                ]
            ],
            [
                'dir_name' => 'CONTRACTS',
                'sub_folder' => [

                    ['dir_name' => 'CTS'],
                    ['dir_name' => 'DAS'],
                ]
            ],
        ]
    ],
    [
        'dir_name' => 'TREASURY'
    ],
    [
        'dir_name' => 'LEGAL'
    ],
);

/* Basic Validation for existing Folder */
if (!file_exists($buyer_name)) {
    mkdir($buyer_name);
}

/* Scan directory*/
$dir = scandir($buyer_name);

/* Loop $buyer_name directory */
foreach ($dir as $d) {

    foreach ($directory_tree as $directory) {

        /* Basic Validation for existing Folder */
        if (!file_exists("$buyer_name/${directory['dir_name']}")) {
            /* Create First Parent Folder  */
            mkdir("$buyer_name/${directory['dir_name']}");
        }
        /* Basic Validation if has sub folder */
        if (array_key_exists('sub_folder', $directory)) {
            /* Check if sub folder has value */
            if (is_array($directory['sub_folder'])) {

                /* Loop sub directory directory */
                foreach ($directory['sub_folder'] as $sub) {

                    /* Basic Validation for existing Sub Folder */
                    if (!file_exists("$buyer_name/${directory['dir_name']}/${sub['dir_name']}")) {
                        /* Create Sub Dir Folder  */
                        mkdir("$buyer_name/${directory['dir_name']}/${sub['dir_name']}");
                    }

                    /* Basic Validation if has sub folder */
                    if (array_key_exists('sub_folder', $sub)) {
                        /* Check if sub folder has sub folder also */
                        if (is_array($sub['sub_folder'])) {

                            /* Loop sub of sub directory directory */
                            foreach ($sub['sub_folder'] as $inner_sub) {
                                if (!file_exists("$buyer_name/${directory['dir_name']}/${sub['dir_name']}/${inner_sub['dir_name']}")) {
                                    /* Create Innder Sub Dir Folder  */
                                    mkdir("$buyer_name/${directory['dir_name']}/${sub['dir_name']}/${inner_sub['dir_name']}");
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
ilagay mo nalang sa CI model mo upon creating buyers name
then i concat mo nalang yung root directory mo before buyers name
 

buhayko

Addict
very thank for slamt kasi my mabait na tumulong sa akn dito kasi ako na stress sir hulog ka tlga nang langit salamt sayo talaga
 

Renzkie_28 papz

Eternal Poster
wait try ko :)

Code:
<?php
/* Folder Name */
$buyer_name = "buyer_name";

/* Directory Structure */
$directory_tree = array(
    [
        'dir_name' => 'CNC',
        'sub_folder' => [
            [
                'dir_name' => 'FILES',
                'sub_folder' => [
                    ['dir_name' => 'SUBMITTED REQUIREMENTS'],
                ]
            ],
            [
                'dir_name' => 'CONTRACTS',
                'sub_folder' => [

                    ['dir_name' => 'CTS'],
                    ['dir_name' => 'DAS'],
                ]
            ],
        ]
    ],
    [
        'dir_name' => 'TREASURY'
    ],
    [
        'dir_name' => 'LEGAL'
    ],
);

/* Basic Validation for existing Folder */
if (!file_exists($buyer_name)) {
    mkdir($buyer_name);
}

/* Scan directory*/
$dir = scandir($buyer_name);

/* Loop $buyer_name directory */
foreach ($dir as $d) {

    foreach ($directory_tree as $directory) {

        /* Basic Validation for existing Folder */
        if (!file_exists("$buyer_name/${directory['dir_name']}")) {
            /* Create First Parent Folder  */
            mkdir("$buyer_name/${directory['dir_name']}");
        }
        /* Basic Validation if has sub folder */
        if (array_key_exists('sub_folder', $directory)) {
            /* Check if sub folder has value */
            if (is_array($directory['sub_folder'])) {

                /* Loop sub directory directory */
                foreach ($directory['sub_folder'] as $sub) {

                    /* Basic Validation for existing Sub Folder */
                    if (!file_exists("$buyer_name/${directory['dir_name']}/${sub['dir_name']}")) {
                        /* Create Sub Dir Folder  */
                        mkdir("$buyer_name/${directory['dir_name']}/${sub['dir_name']}");
                    }

                    /* Basic Validation if has sub folder */
                    if (array_key_exists('sub_folder', $sub)) {
                        /* Check if sub folder has sub folder also */
                        if (is_array($sub['sub_folder'])) {

                            /* Loop sub of sub directory directory */
                            foreach ($sub['sub_folder'] as $inner_sub) {
                                if (!file_exists("$buyer_name/${directory['dir_name']}/${sub['dir_name']}/${inner_sub['dir_name']}")) {
                                    /* Create Innder Sub Dir Folder  */
                                    mkdir("$buyer_name/${directory['dir_name']}/${sub['dir_name']}/${inner_sub['dir_name']}");
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
ilagay mo nalang sa CI model mo upon creating buyers name
then i concat mo nalang yung root directory mo before buyers name
👍 Ganitong members dapat tularan. Hindi nag aatubili na tumulong sa iba i salute you paps ✔
 

buhayko

Addict
Sir walang response xia sa json
----------------------------------------------------------------
public function sample($payload){
// $p_id = (is_null($_POST['section_id']) ? 0 : $_POST['section_id']);
$data = array(
// 'SECTION_ID' => $p_id,
"SECTION_NAME" =>$payload['SECTION_NAME'],
"SECTION_DESC" => $payload['SECTION_DESC'],
"SECTION_TYPE" => $payload['SECTION_TYPE'],
"SECTION_PARENT_ID" => $payload['SECTION_PARENT_ID'],
"SECTION_STATUS" => $payload['SECTION_STATUS'],
"SECTION_PASSWORD"=>$payload['SECTION_PASSWORD'],
"STORAGE_ID"=>$payload['STORAGE_ID'],
"CREATED_DATE"=>$payload['CREATED_DATE'],
"CREATED_BY"=>$payload['CREATED_BY'],
"LASTMODIFIED_BY"=>$payload['LASTMODIFIED_BY'],
"LASTMODIFIED_DATE"=>$payload['LASTMODIFIED_DATE'],

);


$this->db->insert('section', $data);
$id = $this->db->insert_id(); // to get the last inserted id

$buyer_name = $id;
$directory_tree = array(
[
'dir_name' => 'CNC',
'sub_folder' => [
[
'dir_name' => 'FILES',
'sub_folder' => [
['dir_name' => 'SUBMITTED REQUIREMENTS'],
]
],
[
'dir_name' => 'CONTRACTS',
'sub_folder' => [

['dir_name' => 'CTS'],
['dir_name' => 'DAS'],
]
],
]
],
[
'dir_name' => 'TREASURY',
'sub_folder' => [

['dir_name' => 'OR'],
]
],
[
'dir_name' => 'LEGAL',
'sub_folder' => [

['dir_name' => 'TITLES'],
]
],
);

/* Basic Validation for existing Folder */
if (!file_exists($buyer_name)) {
mkdir($buyer_name);
}

/* Scan directory*/
$dir = scandir($buyer_name);

/* Loop $buyer_name directory */
foreach ($dir as $d) {

foreach ($directory_tree as $directory) {

/* Basic Validation for existing Folder */
if (!file_exists("$buyer_name/${directory['dir_name']}")) {
/* Create First Parent Folder */
mkdir("$buyer_name/${directory['dir_name']}");
}
/* Basic Validation if has sub folder */
if (array_key_exists('sub_folder', $directory)) {
/* Check if sub folder has value */
if (is_array($directory['sub_folder'])) {

/* Loop sub directory directory */
foreach ($directory['sub_folder'] as $sub) {

/* Basic Validation for existing Sub Folder */
if (!file_exists("$buyer_name/${directory['dir_name']}/${sub['dir_name']}")) {
/* Create Sub Dir Folder */
mkdir("$buyer_name/${directory['dir_name']}/${sub['dir_name']}");
}

/* Basic Validation if has sub folder */
if (array_key_exists('sub_folder', $sub)) {
/* Check if sub folder has sub folder also */
if (is_array($sub['sub_folder'])) {

/* Loop sub of sub directory directory */
foreach ($sub['sub_folder'] as $inner_sub) {
if (!file_exists("$buyer_name/${directory['dir_name']}/${sub['dir_name']}/${inner_sub['dir_name']}")) {
/* Create Innder Sub Dir Folder */
mkdir("$buyer_name/${directory['dir_name']}/${sub['dir_name']}/${inner_sub['dir_name']}");
}
}
}
}
}
}
}
}
}
$this->db->insert('section', $directory_tree);


$response = array(
'status' => 'SUCCESS',
'message' => 'BUYERNAME ADDED SUCCESSFULLY'
);
echo json_encode($response);

}
 

buhayko

Addict
ito yung sa controller code ko sa postman ko xia ni rrun
------------------------------------------------------------------------------------------------
public function sample(){
$payload = json_decode(file_get_contents('php://input'),true);
$this->Section_model->sample($payload);
}
 

ThePoyPi

Journeyman
ito yung sa controller code ko sa postman ko xia ni rrun
------------------------------------------------------------------------------------------------
public function sample(){
$payload = json_decode(file_get_contents('php://input'),true);
$this->Section_model->sample($payload);
}
na try mo na bang idebug yung code mo paps?
check mo if nakak insert siya sa database


Code:
    $this->db->insert('section', $data);
 

Trending Topics

Trending On This Forum

Unanswered Topics

Top