Fix ValueError: finfo_file() Argument #2 must not be empty #54
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The addon was throwing a
ValueErrorwhenfinfo_file()was called with an empty filename parameter:This error occurred in PHP 8.1+ when file uploads failed but the
$_FILESarray was still populated. In such cases,$uploadedFile['tmp_name']could be empty, causingfinfo_file()to throw a ValueError when attempting to validate the MIME type.Solution
Added proper validation checks before calling
finfo_file()in thehandleFileUploadWithResult()method:$uploadedFile['error']to catch PHP upload errors (file size exceeded, incomplete uploads, etc.)$uploadedFile['tmp_name']is not empty before using itis_uploaded_file()to verify the file was legitimately uploaded via HTTP POSTThese checks ensure that MIME type validation is only performed on valid uploaded files, preventing the ValueError and providing better error messages to users.
Changes
/lib/zip_install.phpin thehandleFileUploadWithResult()methodBenefits
Testing
Original prompt
This section details on the original issue you should resolve
<issue_title>ValueError: finfo_file(): Argument #2 ($filename) must not be empty</issue_title>
<issue_description>ValueError: finfo_file(): Argument #2 ($filename) must not be empty
File: redaxo/src/addons/zip_install/lib/zip_install.php
Line: 401
Stacktrace
System report (REDAXO 5.20.0, PHP 8.4.13, MySQL 5.7.44)
Fixes #53
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.