skip to Main Content

NOTE: I’m a novice with PHP.

My PHP code uploads small files but silently fails with a test file of about 11M. So, I found a number of related questions, such as this one, and from that found /etc/php.ini, and updated post_max_size to zero and, since it doesn’t appear to have a "don’t set a limit", set upload_max_filesize to 128G – that ought to do it!

But no?!

I stopped Apache and restarted it, reloaded the client-side while testing, but it still doesn’t work.

If you want to see the code – this is only the PHP portion… MAYBE some other aspect of this Apache configuration is holding back my application?

To wit:

<?php

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (isset($_FILES['files'])) {
        $errors = [];
        $path = 'uploads/';
        $extensions = ['jpg', 'jpeg', 'png', 'gif', 'txt', 'mpeg'];
        
        $all_files = count($_FILES['files']['tmp_name']);
        
        for ($i = 0; $i < $all_files; $i++) {
            $file_name = $_FILES['files']['name'][$i];
            $file_tmp = $_FILES['files']['tmp_name'][$i];
            $file_type = $_FILES['files']['type'][$i];
            $file_size = $_FILES['files']['size'][$i];
            $file_ext = strtolower(end(explode('.', $_FILES['files']['name'][$i])));            
            $file = $path . $file_name;                
            move_uploaded_file($file_tmp, $file);
        }

        if ($errors) print_r($errors);
    }
}

An additional issue is that I’m not getting any error output, but then maybe I’m not looking where the print_r code would send it? I’d like it to show up on the client-side’s browser window "on the page."

MAJOR ISSUE

Using phpinfo() illustrates it’s NOT honoring the changes I’m making?!

I proved the point: I’m editing the ONLY php.ini file there is on the system, this is confirmed from the phpinfo() data (below), and when I change it even slightly it is NOT honored!

YES, I’ve been restarting Apache every time.

As a case-in-point, I changed upload_max_filesize from 2M to merely 8M, but the data from phpinfo() doesn’t change.

Note that I’m just doing a reload on a firefox browser to get the new data – could it be caching old data?!

Presuming not, this must be a platform issue?!

Platform data:

PHP Version 8.2.6
System  Linux server1 6.2.9-300.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Mar 30 22:32:58 UTC 2023 x86_64
Build Date  May 9 2023 06:25:31
Build System    Fedora release 38 (Thirty Eight)
Build Provider  Fedora Project
Compiler    gcc (GCC) 13.1.1 20230426 (Red Hat 13.1.1-1)
Architecture    x86_64
Server API  FPM/FastCGI
Virtual Directory Support   disabled
Configuration File (php.ini) Path   /etc
Loaded Configuration File   /etc/php.ini
Scan this dir for additional .ini files     /etc/php.d 

There’s vastly more data available: if anyone can suggest what else I should post, I will!

2

Answers


  1. Chosen as BEST ANSWER

    Well crap: After hours of wasted time and FINALLY realizing that PHP wasn't accepting the changes I found this post that explains SOME ports of PHP are ... -ahem- DIFFERENT and you must, on my distribution, not only restart Apache but also do this:

    systemctl restart php-fpm.service
    

    That worked.

    Note that I'm not inclined to close this question as a duplicate because if my version of the ask had been out there it would have saved me (and others) a LOT of time.

    Thanks to everyone who tried and help me; I learned from you and appreciate it.


  2. Do you have a request with the content-type "application/x-www-form-urlencoded" header ?
    post_max_size set to 0 does not work with some content-type headers.
    https://www.php.net/manual/en/ini.core.php#ini.post-max-size

    Try to specify a value for post_max_size that is at least equal to upload_max_filesize.
    For example:

    post_max_size=128M
    upload_max_filesize=128M
    

    Note that memory_limit must also be at least equal to these 2 parameters.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search