CodeIgniter Forums
Cannot figure out helper FILESYSTEM - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: Cannot figure out helper FILESYSTEM (/showthread.php?tid=89307)



Cannot figure out helper FILESYSTEM - shenko225 - 02-03-2024

[img=856x456]/home/shenko/Pictures/Screenshots/a.png[/img]#---Just List out the files in public/archive CodeIgniter 4.4.4---#

here is my Controller:

PHP Code:
<?php

// app/Controllers/LibraryController.php

namespace App\Controllers;

use 
CodeIgniter\Controller;

class 
LibraryController extends Controller
{
    public function index()
    {
        helper('filesystem');
        $directory FCPATH '/archive'// Path to the library directory

        // Check if the directory exists
        if (is_dir($directory)) {
            $data['files'] = directory_map($directory);
        } else {
            $data['files'] = [];
        }

        return view('library'$data);
    }


# See the /Views/library.php in the next reply


RE: Cannot figure out helper FILESYSTEM - shenko225 - 02-03-2024

# Here is my /Views/pages/library.php

PHP Code:
<section style="background-color: darkgray;">
    <h2>BOOM BOOM POW</h2>
</
section>
<
section style="background-color: darkgray;">
    <h2>Files in the library directory:</h2>
    <ul>
        <?php if (isset($files) && is_array($files)): ?>
            <?php foreach ($files as $file): ?>
                <li><a href="<?= base_url('archive/' $file?>"><?= $file ?></a></li>
            <?php endforeach; ?>
        <?php else: ?>
            <li>No files found.</li>
        <?php endif; ?>
    </ul>
</section> 



RE: Cannot figure out helper FILESYSTEM - kenjis - 02-03-2024

What's your issue?

See https://www.codeigniter.com/user_guide/helpers/filesystem_helper.html#directory_map


RE: Cannot figure out helper FILESYSTEM - Francine - 03-31-2024

This entity should not be validated.
Object that represents a record in a database.