title: How to prevent code from running without a file present
body: <p>Here is my code</p>
  
  <pre><code>if ($error &gt; 0)
     {
     die("Error uploading file! Code $error.");
     }
     else
     {
     if ($type === "image/png" || $type==="image/jpeg" &amp;&amp; $size &lt; 122200000)
     {
     $am = move_uploaded_file($temp,"$uploaded/$name");
     }
     else
     {
         die("Format not allowed or file size too big!");
     }
     }
  </code></pre>
  
  <p>This code works perfectly fine. However, I give the user an option to upload an image. If they do not want to upload an image, then I do not want this code to run. I then rewrote the code as follow:</p>
  
  <pre><code>if(file_exists($_FILES["image"]))
     {
     if ($error &gt; 0)
     {
     die("Error uploading file! Code $error.");
     }
     else
     {
     if ($type === "image/png" || $type==="image/jpeg" &amp;&amp; $size &lt; 122200000)
     {
     $am = move_uploaded_file($temp,"$uploaded/$name");
     }
     else
     {
         die("Format not allowed or file size too big!");
     }
  }
  }
  </code></pre>
  
  <p>After adding this, this code does not run if no file was entered but if a file was entered, it no longer uploads to my directory. Weird. I tried using <strong>isset($_FILES["image])</strong> however that did not work at all. Any thoughts?</p>