Skip to content

Exceeding max_file_uploads causes an apparently unrelated "cannot modify headers" warning before script execution #10654

Closed as not planned
@php4fan

Description

@php4fan

Description

The following code:

<?php

if (!empty($_POST))
    echo "Done.";
else {

?><!DOCTYPE html>
<html>
<head><title>xxxx</title></head>
<body>
    <form method="post" enctype="multipart/form-data">
        <div>Lalalala</div>
        <input type="file" multiple name="diocane[]">
        <input type="hidden" name="something" value="1">
        <button type="submit">Upload</button>
    </form>
</body>
</html>
<?php
}

when uploading 21 files (one more than the value of max_file_uploads), resulted in this output:

Warning: Maximum number of allowable file uploads has been exceeded in Unknown on line 0

Warning: Cannot modify header information - headers already sent in Unknown on line 0
Done.

But I expected this output instead:

Warning: Maximum number of allowable file uploads has been exceeded in Unknown on line 0

I am not attempting to set any header, and yet I get the "cannot modify header information" error. I understand that headers cannot be set because of the output that was generated because of the warning, but again, my code did not attempt to send any header.

It seems that PHP is trying to set some headers, during the startup phase (i.e. before my script gets executed), but:

  1. I'm not sure there's a good reason for that
  2. if there is, do it before you handle uploaded files, or maybe silence the "cannot modify header information" warning when you do.
  3. give more information in the error message so that I can at least figure out what headers failed to be sent.

PHP Version

PHP 7.4.11

Operating System

Debian 10

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions