Welcome Guest, Not a member yet? Register   Sign In
Cannot figure out helper FILESYSTEM
#1
Photo 
(This post was last modified: 02-03-2024, 05:27 PM by kenjis.)

[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
Reply
#2

(This post was last modified: 02-03-2024, 04:52 PM by shenko225.)

# 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> 
Reply
#3

What's your issue?

See https://www.codeigniter.com/user_guide/h...ectory_map
Reply




Theme © iAndrew 2016 - Forum software by © MyBB