Visitar URL original
Resolved issue where uploads to MSM shared upload directories showed a post_max_size error and left files behind when validation failed by robinsowell · Pull Request #5445 · ExpressionEngine/ExpressionEngine · GitHub
Skip to content

Resolved issue where uploads to MSM shared upload directories showed a post_max_size error and left files behind when validation failed - #5445

Draft
robinsowell wants to merge 1 commit into
7.devfrom
fix/shared-upload-dir-legacy-prefs
Draft

robinsowell wants to merge 1 commit into
7.devfrom
fix/shared-upload-dir-legacy-prefs

Conversation

@robinsowell

@robinsowell robinsowell commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Upload directories created with Share Upload Directory on all sites are stored with site_id 0. The modern File models already look them up with site_id IN (0, current) (Service/File/Upload::uploadTo(), the file and file grid fieldtypes, the filepicker). The legacy File_upload_preferences_model::get_file_upload_preferences() still filtered site_id = current, so it never found a shared directory.

The visible symptom on MSM sites:

  1. Upload a file to a shared directory that fails a post-move check. Reproduce reliably by dropping a .webp into a shared directory that allows only Documents.
  2. Filemanager::_upload_error() calls file_model::delete_raw_file(), which looks the directory up through the legacy model and gets an empty result.
  3. PHP raises Undefined array key "server_path" (legacy/models/file_model.php:634). The HTML error output replaces the JSON response, so the drag-and-drop uploader shows the generic "Unexpected error. Check your post_max_size setting" message instead of the real error ("file type not allowed", "exceeds max dimensions", etc.).
  4. The @unlink() calls run against a null path, so the file that should have been cleaned up stays in the directory. Users report that the upload "errored but uploaded anyway".

Non-MSM installs and non-shared directories are unaffected, which is why this is hard to reproduce locally.

Change

get_file_upload_preferences() now filters where_in('site_id', [0, current_site_id]) unless $ignore_site_id is passed, matching the modern models. This fixes delete_raw_file() and the other legacy callers that look up a shared directory by ID (Filemanager::fetch_files(), metaweblog, moblog). List callers now include shared directories, which matches the modern file pickers and fieldtypes. parse_upload_path_vars() already handles site_id 0 (no per-site overrides).

Tests

  • New Tests/ExpressionEngine/legacy/Models/FileUploadPreferencesModelTest.php: an ID lookup includes site_id 0 and returns server_path; $ignore_site_id skips the site filter. It fails on 7.dev without the change.
  • Addons/file (232), Service/File (11), Library/Filesystem (10), legacy/Helpers, legacy/Core, legacy/database, legacy/Api: same results before and after.
  • Pre-existing failures on 7.dev, unchanged by this PR: GridModelOrderingTest::testOrdersByMultipleGridColumns ("Cannot call constructor") and CacheAdapterFallbackToFileTest::testDefaultsToFileAdapter (child process ended unexpectedly). Locally the full suite also stops at about 10% with "The configuration file does not exist.", so it was run by area.

Upload directories shared across all MSM sites are stored with site_id 0.
The legacy file_upload_preferences_model only matched the current site_id,
while the modern models use site_id IN (0, current). When an upload to a
shared directory failed validation, Filemanager::_upload_error() ->
file_model::delete_raw_file() found no row and raised "Undefined array key
server_path"; the HTML warning broke the drag-and-drop XHR (shown as the
generic post_max_size error) and left the partially uploaded file on disk.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@robinsowell robinsowell added the Bug: Accepted Bug has been confirmed, is reproducible, and ready to work on. label Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug: Accepted Bug has been confirmed, is reproducible, and ready to work on.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant