Back to list

Fix Moodle file upload error with spaces in filename on aaPanel

Cover

When running Moodle on an aaPanel-managed server, uploading files with spaces in the name may fail or not load. This is often because Apache/Nginx do not decode the URL correctly when Moodle uses PATH_INFO. This post describes a quick fix in Moodle core.

Moodle admin — broken logo/image due to server/URL encoding
Related symptom: logo or static assets not loading (broken image) on Moodle admin — can be caused by PATH_INFO/URL not being decoded.

1. The problem

Files without spaces in the name upload fine; files with spaces (e.g. bai tap.pdf, lecture slide.pdf) fail. The cause is usually incorrect URL handling of PATH_INFO by the server.

2. Cause

Moodle uses $_SERVER['PATH_INFO'] for file paths. On some setups (especially aaPanel + Nginx/Apache), this value can remain URL-encoded (e.g. bai%20tap.pdf). Without decoding, Moodle cannot find the real file.

3–6. Fix

Edit Moodle core file lib/weblib.php (e.g. /www/wwwroot/moodle/lib/weblib.php). Find:

$relativepath = $_SERVER['PATH_INFO'];

Replace with:

$relativepath = urldecode($_SERVER['PATH_INFO']);

7–8. Why it works

urldecode() turns bai%20tap.pdf into bai tap.pdf, so Moodle resolves the correct filesystem path.

9–10. After editing

Restart Apache or Nginx in aaPanel.

11–13. Testing and notes

Test uploads with names like bai tap.pdf, lecture slide.pptx. Because this changes core, re-check lib/weblib.php after any Moodle upgrade. For a long-term approach, you can adjust Nginx/Apache rewrite rules so the server decodes URLs correctly; the weblib.php change is the quickest fix.

Conclusion

The issue is PATH_INFO not being decoded. Using $relativepath = urldecode($_SERVER['PATH_INFO']); resolves it.