getgrav / getgrav/grav-plugin-form
PHP file upload error from backend shows success
- Dominant language
- PHP
- Stars
- 64
- Forks
- 80
- Avg merge
- 10h 13m
- Merged PRs (30d)
- 9
Description
If there is a PHP file upload error when handling a file upload (eg. https://www.php.net/manual/en/features.file-upload.errors.php) the frontend still shows success.
Reproduction steps:
1. Create a page with a file upload field.
1. Change the permissions on PHP's `upload_tmp_dir` directory to cause a permission error.
1. Select a file for upload, which gets uploaded via AJAX before the form is submitted.
1. Note the tick mark that indicates a successful upload.
1. Use the browser dev tools to see that the response from the server for the POST to `task:file-upload` was `{"status":"error","message":"Unable to upload file filename.txt: "}`.
I took a look at the code in the `handleError` function in `app/fields/file.js` line 206 and it simple returns true. This code should probably display a failure and show the error message returned from the backend.
Also, the error message returned from the backend doesn't look to be complete. I will submit a pull request to fix this in a bit.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in app/fields/file.js around the handleError function at line 206, then trace the AJAX response from the task:file-upload endpoint. Reproduce the upload_tmp_dir permission failure and verify that the frontend no longer shows a success tick when the response has status error, while the backend error message is complete.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, php
- Domain
- backend, frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100