Skip to content

fix #1246 and #1415: settings save no longer corrupts config.php#1421

Open
nerun wants to merge 1 commit into
prasathmani:masterfrom
nerun:settings-save-fix
Open

fix #1246 and #1415: settings save no longer corrupts config.php#1421
nerun wants to merge 1 commit into
prasathmani:masterfrom
nerun:settings-save-fix

Conversation

@nerun

@nerun nerun commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

This is a robust fix for issues #1246 and #1415.

Issue

When using an external config.php based on the official config-sample.txt, saving settings from the UI can corrupt the config file and make Tiny File Manager fail with HTTP 500.

The official sample starts like this:

<?php

/*

This is valid PHP.

But the settings save mechanism appears to blindly overwrite the first three lines of config.php with:

<?php
//Default Configuration
$CONFIG = '...';

So the opening /* of the comment block is removed, while the rest of the comment remains in the file.

Result after saving:

<?php
//Default Configuration
$CONFIG = '...';
################################################################
...
*/

This makes config.php invalid PHP and Tiny File Manager no longer loads - HTTP 500.

Expected behavior

The settings save mechanism should not blindly replace the first three lines of config.php.

Fix adopted by this PR

Instead of blindly overwriting the first three lines of config.php, this fix locates and replaces only the existing $CONFIG = ...; assignment line, leaving the rest of the file (including comments, blank lines, and any custom structure) completely untouched.

Behavior:

  • If $CONFIG already exists: only that line is replaced with the updated value. All other lines, including comment blocks like /* ... */, remain exactly as they were.
  • If $CONFIG does not exist yet (e.g. a fresh config.php based on config-sample.txt): the new $CONFIG = ...; line is inserted right after the opening <?php tag, without deleting or altering anything else in the file.
  • Fallback safety net: if the <?php tag itself can't be matched for some unexpected reason, the new line is prepended along with <?php, still preserving the entire original content.

This ensures the settings save mechanism never assumes a fixed line structure for config.php, which was the root cause of the corruption described above. Both the default config.php and any custom file based on config-sample.txt (with its leading comment block) now save safely without breaking PHP syntax.

@nerun nerun force-pushed the settings-save-fix branch from dedeec4 to aab356a Compare July 6, 2026 02:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants