title: make validation for upload picture only (php)
body: <p>I have 2 questions.</p>
  
  <p>my first question--
  I am using a HTML form to upload image files. Now i am using validation to allow the file types.
  When i was searched through google i found this.</p>
  
  <p></p>
  
  <p>But when I change with "all file" When selecting a picture, Users can send data that is not an image.
  My question is here, How to make validation for upload only image and big file below 2mb</p>
  
  <p>my second question--
  How to validate when people don't fill the file, I've tried this "!isset($picture))"
  But it doesn't work.</p>
  
  <p>[code]-->start</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  
  &lt;?php
  
  require_once "db.php";
  require_once "function.php";
  
  
  
  if( isset($_POST['submit']) ){
  
    $name     = $_POST['name'];
    $info     = $_POST['info'];
    $picture  = $_FILES['picture'];
  
  
    if(!empty(trim($name)) &amp;&amp; !empty(trim($info)) ) {
  
          if(add_data($name, $info, $picture)) {
        echo "success";
      }else{
        echo "fail";
      }
  
    }else{
      echo 'The data is empty';
    }
  }
  
  
  ?&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
  
  
  &lt;form action="" method="post" enctype="multipart/form-data"&gt;
  
  &lt;table&gt;
    &lt;tr&gt;
      &lt;td&gt;Name&lt;/td&gt;
      &lt;td&gt;:&lt;/td&gt;
      &lt;td&gt;&lt;input type="text" name="name"&gt;&lt;/td&gt;
    &lt;/tr&gt;
  
    &lt;tr&gt;
      &lt;td&gt;Info&lt;/td&gt;
      &lt;td&gt;:&lt;/td&gt;
      &lt;td&gt;&lt;textarea name="info"&gt;&lt;/textarea&gt;&lt;/td&gt;
    &lt;/tr&gt;
  
    &lt;tr&gt;
      &lt;td&gt;picture&lt;/td&gt;
      &lt;td&gt;:&lt;/td&gt;
      &lt;td&gt;&lt;input type="file" accept="image/*"  name="picture"&gt;&lt;/td&gt;
    &lt;/tr&gt;
  
    &lt;tr&gt;
      &lt;td&gt;&lt;/td&gt;
      &lt;td&gt;&lt;/td&gt;
      &lt;td&gt;&lt;button type="submit" name="submit"&gt;Save&lt;/button&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;/table&gt;
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>[/code]-->end</p>
  
  <p>[code]function-->start</p>
  
  <pre><code>&lt;?php
  
  function add_data($name, $info, $picture){
  global $connect;
  
  
  
  $name = mysqli_real_escape_string($connect, $name);
  $info = mysqli_real_escape_string($connect, $info);
  
  
  $filePath = "file/".basename($picture["name"]);
  move_uploaded_file($picture["tmp_name"], $filePath);
  
  
  $query = "INSERT INTO try (name, info, picture) VALUES ('$name', '$info', '$filePath')";
  
  if( mysqli_query($connect, $query) ){
  
        return true;
      }else{
        return false;
  }
  }
  ?&gt;
  </code></pre>
  
  <p>[/code]-->end</p>