'Codeigniter - How to view files content from a different directory
I'm quite new with Codeigniter. I managed to create a list displaying the files located in different folder with the below link:
https://mywebsite/index.php/report/generateList
However, when I click on the link links generated, it shows the 404 Page Not Found error.
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 I click on it?
Here is my code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Report extends CI_Controller {
public function index()
{
echo 'Hello!';
}
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!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
