title: Checking if file is larger than 1 MB
body: <p>I would like to ask your help. I wrote a code which checks if all the fields are filled in and if the file is not larger than 1 MB. If everything is correct the file successfuly uploads to MySQL database. But if the file size is larger than 1 MB the code stops working. The error doesnt show up and all the fields become empty. Here`s the code (some of it is in Lithuanian, sorry):</p>
  
  <pre><code>&lt;?php
  error_reporting(E_ERROR);
  session_start();
  if (isset($_SESSION['login'])){ 
      include 'config.php';
      $username = $_SESSION['login'];
      $result = mysqli_query($db,"SELECT * FROM users WHERE username='$username'");
      $rws = mysqli_fetch_array($result);
      if($_SERVER['REQUEST_METHOD'] == 'POST') {
      $autorius = mysqli_real_escape_string($db,$_POST['autorius']);$pavadinimas = mysqli_real_escape_string($db,$_POST['pavadinimas']);$puslapiai = mysqli_real_escape_string($db,$_POST['puslapiai']);$tema = mysqli_real_escape_string($db,$_POST['tema']);$pmintis = mysqli_real_escape_string($db,$_POST['pmintis']);$pveikejai = mysqli_real_escape_string($db,$_POST['pveikejai']);$aveikejai = mysqli_real_escape_string($db,$_POST['aveikejai']);$epizodas = mysqli_real_escape_string($db,$_POST['epizodas']);$nuomone = mysqli_real_escape_string($db,$_POST['nuomone']);$apie = mysqli_real_escape_string($db,$_POST['apie']);$foto = mysqli_real_escape_string($db,$_POST['foto']);$user_id = $rws['id'];
      if (!empty($autorius) &amp;&amp; !empty($pavadinimas) &amp;&amp; !empty($puslapiai) &amp;&amp; !empty($tema) &amp;&amp; !empty($pmintis) &amp;&amp; !empty($pveikejai) &amp;&amp; !empty($aveikejai) &amp;&amp; !empty($epizodas) &amp;&amp; !empty($nuomone) &amp;&amp; !empty($apie) &amp;&amp; isset($foto) &amp;&amp; $_FILES['foto']['size'] &gt; 0 &amp;&amp; $_FILES['foto']['size'] &lt; 1000001) {
          $fileName = $_FILES['foto']['name'];$tmpName  = $_FILES['foto']['tmp_name'];$fileSize = $_FILES['foto']['size'];$fileType = $_FILES['foto']['type'];
          $fp = fopen($tmpName, 'r');
          $foto = fread($fp, filesize($tmpName));
          $foto = addslashes($foto);
          fclose($fp);
          $query = "INSERT INTO books (id_user, autorius, pavadinimas, puslapiai, tema, pmintis, pveikejai, aveikejai, epizodas, nuomone, apie, foto, name, type, size) ".
          "VALUES ('$user_id', '$autorius', '$pavadinimas', '$puslapiai', '$tema', '$pmintis', '$pveikejai', '$aveikejai', '$epizodas', '$nuomone', '$apie', '$foto', '$fileName', '$fileType', '$fileSize')";
          $result = mysqli_query($db,$query);
          $success = "Knygos aprašymas įkeltas";
          echo $_FILES['foto']['size'];
      }
      else if (empty($autorius) || empty($pavadinimas) || empty($puslapiai) || empty($tema) || empty($pmintis) || empty($pveikejai) || empty($aveikejai) || empty($epizodas) || empty($nuomone) || empty($apie)) {
          $error = "Užpildykite visus laukelius!";
      }
      else if (empty($foto)){
          $error = "Pasirinkite viršelio nuotrauką!";
      }
      else if ($_FILES['foto']['size'] &gt; 1000001){
          $error = "Viršelio nuotraukos dydid neturi viršyti 1 MB!";
      }
      }
  ?&gt;
  &lt;?php include 'bin/includes/header.html'; ?&gt;
      &lt;div class="container"&gt;
  
          &lt;div class="row"&gt;
              &lt;div class="col-lg-12"&gt;
                  &lt;h1 class="page-header"&gt;Įkelti knygos aprašymą
                      &lt;small&gt;Ikelkite savo knygos aprašymą&lt;/small&gt;
                  &lt;/h1&gt;
                  &lt;ol class="breadcrumb"&gt;
                      &lt;li&gt;&lt;a href="index.php"&gt;Pagrindinis&lt;/a&gt;
                      &lt;/li&gt;
                      &lt;li class="active"&gt;Įkelti knygos aprašymą&lt;/li&gt;
                  &lt;/ol&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="row"&gt;
              &lt;div class="col-md-8"&gt;
                  &lt;form name="upload" id="upload" method="post" enctype="multipart/form-data"&gt;
                      &lt;div class="control-group form-group"&gt;
                          &lt;?php
                          if(isset($success)) {
                              echo '&lt;label style="color: #44FF00;"&gt;';
                              echo $success;
                              echo '&lt;/label&gt;';
                          }
                          else {
                              echo '&lt;label style="color: #FF3700;"&gt;';
                              echo $error;
                              echo '&lt;/label&gt;';
                          } ?&gt;
                          &lt;div class="controls"&gt;
                              &lt;input type="text" class="form-control" name="autorius" maxlength="60" placeholder="Autorius" value="&lt;?php if(!empty($_POST['autorius'])) echo $_POST['autorius'];?&gt;"&gt;
                              &lt;p class="help-block"&gt;&lt;/p&gt;
                          &lt;/div&gt;
                          &lt;div class="controls"&gt;
                              &lt;input type="text" class="form-control" name="pavadinimas" maxlength="255" placeholder="Pavadinimas" value="&lt;?php if(!empty($_POST['pavadinimas'])) echo $_POST['pavadinimas'];?&gt;"&gt;
                              &lt;p class="help-block"&gt;&lt;/p&gt;
                          &lt;/div&gt;
                          &lt;div class="controls"&gt;
                              &lt;input type="text" class="form-control" name="puslapiai" placeholder="Puslapių skaičius" value="&lt;?php if(!empty($_POST['puslapiai'])) echo $_POST['puslapiai'];?&gt;"&gt;
                              &lt;p class="help-block"&gt;&lt;/p&gt;
                          &lt;/div&gt;
                          &lt;div class="controls"&gt;
                              &lt;input type="text" class="form-control" name="pveikejai" maxlength="999" placeholder="Pagrindiniai veikėjai" value="&lt;?php if(!empty($_POST['pveikejai'])) echo $_POST['pveikejai'];?&gt;"&gt;
                              &lt;p class="help-block"&gt;&lt;/p&gt;
                          &lt;/div&gt;
                          &lt;div class="controls"&gt;
                              &lt;input type="text" class="form-control" name="aveikejai" maxlength="999" placeholder="Antraeiliai veikėjai" value="&lt;?php if(!empty($_POST['aveikejai'])) echo $_POST['aveikejai'];?&gt;"&gt;
                              &lt;p class="help-block"&gt;&lt;/p&gt;
                          &lt;/div&gt;
                          &lt;div class="controls"&gt;
                              &lt;textarea placeholder="Tema" rows="2" class="form-control" name="tema" maxlength="999" style="resize:none"&gt;&lt;?php if(!empty($_POST['tema'])) echo $_POST['tema'];?&gt;&lt;/textarea&gt;
                              &lt;p class="help-block"&gt;&lt;/p&gt;
                          &lt;/div&gt;
                          &lt;div class="controls"&gt;
                              &lt;textarea placeholder="Pagrindinė mintis" rows="2" class="form-control" name="pmintis" maxlength="999" style="resize:none"&gt;&lt;?php if(!empty($_POST['pmintis'])) echo $_POST['pmintis'];?&gt;&lt;/textarea&gt;
                              &lt;p class="help-block"&gt;&lt;/p&gt;
                          &lt;/div&gt;
                          &lt;div class="controls"&gt;
                              &lt;textarea placeholder="Siužetas" rows="5" class="form-control" name="apie" maxlength="2999" style="resize:none"&gt;&lt;?php if(!empty($_POST['apie'])) echo $_POST['apie'];?&gt;&lt;/textarea&gt;
                              &lt;p class="help-block"&gt;&lt;/p&gt;
                          &lt;/div&gt;
                          &lt;div class="controls"&gt;
                              &lt;textarea placeholder="Įsimintiniausias epizodas" rows="3" class="form-control" name="epizodas" maxlength="2999" style="resize:none"&gt;&lt;?php if(!empty($_POST['epizodas'])) echo $_POST['epizodas'];?&gt;&lt;/textarea&gt;
                              &lt;p class="help-block"&gt;&lt;/p&gt;
                          &lt;/div&gt;
                          &lt;div class="controls"&gt;
                              &lt;textarea placeholder="Nuomonė apie knygą" rows="3" class="form-control" name="nuomone" maxlength="999" style="resize:none"&gt;&lt;?php if(!empty($_POST['nuomone'])) echo $_POST['nuomone'];?&gt;&lt;/textarea&gt;
                              &lt;p class="help-block"&gt;&lt;/p&gt;
                          &lt;/div&gt;
                          &lt;div class="controls"&gt;
                              &lt;label&gt;Įkelti viršelį (max 1MB)&lt;/label&gt;
                              &lt;input name="foto" type="file" id="foto"&gt; 
                              &lt;p class="help-block"&gt;&lt;/p&gt;
                          &lt;/div&gt;
                          &lt;button type="submit" class="btn btn-primary"&gt;Įkelti&lt;/button&gt;
                      &lt;/div&gt;
                  &lt;/form&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
  &lt;?php include 'bin/includes/footer.html'; ?&gt;
  &lt;?php } else {
      header("location: index.php");
  }
  </code></pre>
  
  <p>Thanks for your help!</p>