Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You're combining three conditions in your if statements here and if one of them fails, the <code>else</code> block will execute. But it won't tell you which condition failed.</p> <pre><code>if ( in_array($extension, $allowedExts) &amp;&amp; $_FILES["file"]["size"]&lt;5242880 &amp;&amp; $_FILES["file"]["error"]&lt;=0) { </code></pre> <p>Here: </p> <ul> <li><p><code>in_array($extension, $allowedExts)</code> — from your <code>var_dump</code> output, this seems to be correct.</p></li> <li><p><code>$_FILES["file"]["error"]&lt;=0)</code> — this is okay, but you don't need to check if it is <em>less</em> than 0. The errors range from 1 to 8 and won't go below 0, but that won't be causing any issues though.</p></li> <li><p><code>$_FILES["file"]["size"]&lt;5242880</code> — this could be failing. Check your <code>php.ini</code> configurations and find out what <code>upload_max_size</code> is. If it's less than the filesize of your file, the condition will fail and the else block will execute.</p></li> </ul> <p>For troubleshooting purposes, I'd recommend splitting the <code>if</code> statements in separate blocks. That way, you'll understand which part is executing and will help you find out why.</p> <p>An example:</p> <pre><code>$check = True; if (!condition) { $check = False; } if (!condition) { $check = False; } if (!condition) { $check = False; } if ($check == True) { # code... } </code></pre> <hr> <p>Here are some other minor improvements for your code:</p> <p>You're currently using:</p> <pre><code>$extension = end(explode(".", $_FILES["file"]["name"])); </code></pre> <p>to get the image extension. This could fail if the extension is in different case.</p> <p>Change this to:</p> <pre><code>$extension = strotolower( end(explode(".", $_FILES["file"]["name"])) ); </code></pre> <p>or better yet:</p> <pre><code>$extension = strtolower( pathinfo($_FILES["file"]["name"], PATHINFO_EXTENSION) ); </code></pre> <p>Second, you're using <code>$time</code> variable in the following statement:</p> <pre><code>$file = $time . "=" . $rand . "=" . $tempfile; </code></pre> <p>That variable isn't defined anywhere and PHP will throw an <code>Undefined variable</code> error when you run the script. Change it to:</p> <pre><code>$time = time(); $file = $time . "=" . $rand . "=" . $tempfile; </code></pre> <p>Hope this helps!</p>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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