CodeIgniter Forums
How to view files content from a different directory - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: How to view files content from a different directory (/showthread.php?tid=81430)



How to view files content from a different directory - tonyharden - 03-01-2022

Hi all, I'm trying to create links to the files located in different folder with the below link structure(just for reference):

https://mywebsite/index.php/report/generateList

However, when I click on the link links generated, it shows an error 404 Page Not Found.

The folder in question, is in a completely different location(not within Codeigniter directory). So I was wondering if anyone can shed some light on how I can create the link to view the content of the files when click on it?

Here is my code:

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Report extends CI_Controller {

        public function generateList()
        {

                $directory "/apps/text_files/";

                if (is_dir($directory))
                {
                        if ($opendirectory opendir($directory))
                        {
                                while (($file readdir($opendirectory)) !== false)
                                {
                                        echo "<a href='$directory"$file'>$file</a>"."<br>";
                                }
                        closedir($opendirectory);
                        }
                }
        }



Thank you in advance!


RE: How to view files content from a different directory - InsiteFX - 03-02-2022

Can you show us your directory structure?
app
system
public
-- assets
-- index.php
etc;

You can try this:
PHP Code:
$directory "/apps/text_files/";

// Try this ../ is up one directory
$directory "apps/text_files/"