[GH-ISSUE #1192] Feature Request: Add index.html for New Folders #763

Open
opened 2026-03-02 16:01:17 +03:00 by kerem · 4 comments
Owner

Originally created by @salahjaafar on GitHub (May 25, 2024).
Original GitHub issue: https://github.com/prasathmani/tinyfilemanager/issues/1192

Dear TinyFileManager Team,

I'm a big fan of TinyFileManager and use it regularly. I'd like to suggest a small but helpful feature: adding an index.html file automatically when creating a new folder. This would prevent directory listing and improve security for those who expose TinyFileManager to the web.

Thank you for considering my suggestion.

Sincerely,
Salah

Originally created by @salahjaafar on GitHub (May 25, 2024). Original GitHub issue: https://github.com/prasathmani/tinyfilemanager/issues/1192 Dear TinyFileManager Team, I'm a big fan of TinyFileManager and use it regularly. I'd like to suggest a small but helpful feature: adding an index.html file automatically when creating a new folder. This would prevent directory listing and improve security for those who expose TinyFileManager to the web. Thank you for considering my suggestion. Sincerely, Salah
Author
Owner

@salahjaafar commented on GitHub (May 25, 2024):

Hello @prasathmani I've developed a small addition to address this.

Here's the code to add in the tinyfilemanager.php file:

// after the line elseif (@is_dir($new_path) && $file != '.' && $file != '..' && fm_is_exclude_items($file)) {
$indexFile = $new_path . '/index.html';
if (!file_exists($indexFile)) {
    $newFile = fopen($indexFile, 'w');
    fwrite($newFile, '<!DOCTYPE html><html><head><title>Index</title></head><body></body></html>');
    fclose($newFile);
}

This code creates a basic index.html file in any directory that doesn't have one, which can be helpful to prevent directory listing vulnerabilities and improve navigation.

I hope this contribution is useful to you.

Best regards,

Salah

<!-- gh-comment-id:2131416152 --> @salahjaafar commented on GitHub (May 25, 2024): Hello @prasathmani I've developed a small addition to address this. Here's the code to add in the tinyfilemanager.php file: ``` // after the line elseif (@is_dir($new_path) && $file != '.' && $file != '..' && fm_is_exclude_items($file)) { $indexFile = $new_path . '/index.html'; if (!file_exists($indexFile)) { $newFile = fopen($indexFile, 'w'); fwrite($newFile, '<!DOCTYPE html><html><head><title>Index</title></head><body></body></html>'); fclose($newFile); } ``` This code creates a basic index.html file in any directory that doesn't have one, which can be helpful to prevent directory listing vulnerabilities and improve navigation. I hope this contribution is useful to you. Best regards, Salah
Author
Owner

@ZeroSuf3r commented on GitHub (May 26, 2024):

Did something similar, but in my case i'm adding index.php.

                $fp_index = fopen($path . '/' . $new . '/' . "index.php", 'w');
                fwrite($fp_index, "<?php require_once('" . $root_path . "/index.php'); exit();?>");
                fclose($fp_index);
<!-- gh-comment-id:2132156809 --> @ZeroSuf3r commented on GitHub (May 26, 2024): Did something similar, but in my case i'm adding **index.php**. ``` $fp_index = fopen($path . '/' . $new . '/' . "index.php", 'w'); fwrite($fp_index, "<?php require_once('" . $root_path . "/index.php'); exit();?>"); fclose($fp_index); ```
Author
Owner

@salahjaafar commented on GitHub (May 26, 2024):

Did something similar, but in my case i'm adding index.php.

                $fp_index = fopen($path . '/' . $new . '/' . "index.php", 'w');
                fwrite($fp_index, "<?php require_once('" . $root_path . "/index.php'); exit();?>");
                fclose($fp_index);

Yes, the choice is yours, but index.html files are simple static files, whereas PHP requires additional processing by the Apache server.

<!-- gh-comment-id:2132180043 --> @salahjaafar commented on GitHub (May 26, 2024): > Did something similar, but in my case i'm adding **index.php**. > > ``` > $fp_index = fopen($path . '/' . $new . '/' . "index.php", 'w'); > fwrite($fp_index, "<?php require_once('" . $root_path . "/index.php'); exit();?>"); > fclose($fp_index); > ``` Yes, the choice is yours, but index.html files are simple static files, whereas PHP requires additional processing by the Apache server.
Author
Owner

@salahjaafar commented on GitHub (May 26, 2024):

@prasathmani
I have improved the code to check if there is also an index.php. Do not create an index.html file because it causes me problems with applications that run in the folder and sub folders.

// after the line elseif (@is_dir($new_path) && $file != '.' && $file != '..' && fm_is_exclude_items($file)) {
$indexHtmlFile = $new_path . '/index.html';
$indexPhpFile = $new_path . '/index.php';

if (!file_exists($indexHtmlFile) && !file_exists($indexPhpFile)) { // Check both files
    $newFile = fopen($indexHtmlFile, 'w');
    fwrite($newFile, '<!DOCTYPE html><html><head><title>Index</title></head><body></body></html>');
    fclose($newFile);
}
<!-- gh-comment-id:2132404421 --> @salahjaafar commented on GitHub (May 26, 2024): @prasathmani I have improved the code to check if there is also an index.php. Do not create an index.html file because it causes me problems with applications that run in the folder and sub folders. ``` // after the line elseif (@is_dir($new_path) && $file != '.' && $file != '..' && fm_is_exclude_items($file)) { $indexHtmlFile = $new_path . '/index.html'; $indexPhpFile = $new_path . '/index.php'; if (!file_exists($indexHtmlFile) && !file_exists($indexPhpFile)) { // Check both files $newFile = fopen($indexHtmlFile, 'w'); fwrite($newFile, '<!DOCTYPE html><html><head><title>Index</title></head><body></body></html>'); fclose($newFile); } ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tinyfilemanager#763
No description provided.