Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP: What's the point of UPLOAD_ERR_INI_SIZE?
    primarykey
    data
    text
    <p>The PHP manual has a section called <a href="http://www.php.net/manual/en/features.file-upload.php" rel="nofollow">Handling file uploads</a>. That section has a subsection called <a href="http://www.php.net/manual/en/features.file-upload.errors.php" rel="nofollow">Error Messages Explained</a>. That subsection describes an error called "UPLOAD_ERR_INI_SIZE":</p> <p>Value: 1; The uploaded file exceeds the <a href="http://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize" rel="nofollow">upload_max_filesize</a> directive in <em>php.ini</em>.</p> <p>However, in my experience, it's impossible to ever check for this particular error using UPLOAD_ERR_INI_SIZE because if a user ever does upload a file that exceeds the upload_max_filesize directive in php.ini, the $_FILES superglobal is empty. Want to test it for yourself? Save this as "upload_test.php" and then try to upload a file that's under the limit and then a file that's over the limit:</p> <pre><code>&lt;?php if (isset($_GET['submitted']) &amp;&amp; $_GET['submitted'] === 'true') { echo 'Contents of $_POST:&lt;hr&gt;&lt;pre&gt;'; print_r($_POST); echo '&lt;/pre&gt;&lt;hr&gt;Contents of $_FILES:&lt;hr&gt;&lt;pre&gt;'; print_r($_FILES); echo '&lt;/pre&gt;&lt;hr&gt;'; exit; } $max_filesize_in_mib = min((int)(ini_get('upload_max_filesize')), (int)(ini_get('post_max_size')), (int)(ini_get('memory_limit'))); ?&gt; &lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt; &lt;title&gt;PHP Upload Test&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;Upload a File (Maximum File Size: &lt;?php echo $max_filesize_in_mib; ?&gt; MiB)&lt;/h1&gt; &lt;form action="upload_test.php?submitted=true" enctype="multipart/form-data" method="post"&gt; &lt;input type="file" name="upload_test"&gt; &lt;input type="hidden" name="random_field" value="You should see this field in the $_POST superglobal."&gt; &lt;input type="submit" value="Upload"&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>So my question is this: what's the point of UPLOAD_ERR_INI_SIZE if you can never check for it?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload