I have an admin section where we can upload media files. Smaller files (around 1 meg) work fine. When the file is too large though nothing happens. It reloads the page just fine as if I didn't upload anything. I did

foreach ($_FILES['mainpic'] as $key => $value) echo "$key: $value<br>";

to test it out and PHP gave the usual error when an array has nothing in it. Any ideas?

    1. Does PHP output any errors? Are you even allowing it to show you errors (e.g. "display_errors" and "error_reporting") ?

    2. What is the upload_max_filesize directive set to?

      Hey brad you've been helpin out a lot lately eh? Thanks. I have error reporting on, I suppose upload_max_filesize is also in my php.ini file. I completely forgot about that since I haven't worked with such big files before, just read about the setting. I'm gonna try it out in the office tomorrow, changing it in the script instead of the ini.

        Shawazi wrote:

        I'm gonna try it out in the office tomorrow, changing it in the script instead of the ini.

        Actually, if you look at the php.ini directives appendix, you'll find that this directive can only be changed in 3 ways: changing it in php.ini, creating a .htaccess file in the directory and using "php_value", or by adding a similar value to Apache's httpd.conf file.

          .htaccess for the win 🙂 was gonna look it up tomorrow of which ways I can go about using it.

            I tried at the very top of .htaccess

            php_value upload_max_filesize 20M
            

            But still had the same problem.

              I've moved on to editing the php.ini and still nothing. More nothing than before actually. It now just stops on a blank white page. I'm on phone with tech support now ha.

                So my host is being ridiculous. I have made a sample script:

                <? 
                //This is the entire page
                ini_set("memory_limit","100M");
                
                if ($_GET['addIMG'] == "yes")
                {
                    foreach ($_FILES as $key => $value)
                    {
                        echo "<b>$key: $value</b><br>";
                        if (trim($value) == "Array")
                        {
                            echo "----<br>";
                            foreach ($_FILES[$key] as $key2 => $value2)
                                echo "$key2: $value2<br>";
                        }
                    }
                    echo "Done";
                }
                ?>
                <form action='upload_test.php?addIMG=yes' method='post' enctype='multipart/form-data'>
                <input type="file" name="mainpic"><br />
                <input type='submit' class='submit' value='Test File'></td>
                </form>
                

                Any small file upload works fine and outputs something like:

                name: Buy_Now.gif
                type: image/gif
                tmp_name: /tmp/phpcZl8ZZ
                error: 0
                size: 475

                Whereas a larger file (4MB when the limit has been set to 20MB in php.ini) says this:

                name: Missing.mp3
                type:
                tmp_name:
                error: 1
                size: 0

                Any ideas how this could be me and not the server?

                  Well, if you'll look on the manual page for [man]features.file-upload.errors[/man], you'll see this:

                  Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.

                  So, you need to change the upload_max_filesize directive. Do a phpinfo() to see what PHP thinks this value is. I believe the default is only 2MB.

                  EDIT: Also note that there is yet another directive that affects file uploads. So far, we know that you may need to increase the memory limit and upload_max_filesize. In addition, the post_max_size directive must be larger than the upload_max_filesize directive (some overhead should be given for other POST'ed fields).

                    That's exactly what I told them about the error yet they were still doubting me. However I did do a phpinfo, didn't think to do that after 2 hours of support late night. The setting is still 2M on upload_max_filesize. You really can't trust tech support. I am also going to up my post_max_size, which I didn't even know about and they didn't even think to mention.

                    While I'm on the topic, when my script uploads a larger file like 1.8 meg, the CHMOD defaults to 600. The support says they have no answer to this so I have to code in chmod or umask to fix it. Do you know the real answer aside from using a function?

                      So the file's permissions depends on its size?? I have no clue why that would be... all I can do is agree and suggest [man]chmod/man the file to whatever umask you'd like.

                        I found out from the server that there was some PERL at the top of the php.ini that was overwriting the max file size and max post size commands. They didn't tell me what it was, but here's a warning heh.

                          Write a Reply...