title: php multiple file upload, file_exist
body: <p>I'm new to programming in PHP, and I'm trying to make a multiple file upload script, but I don't know how to check if the uploading files already exist! How can I do that? Can you help me?
  This is my code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;form action="upload.php" method="post" enctype="multipart/form-data"&gt;
  &lt;input type="file" name="files[]" multiple&gt;
  &lt;input type="submit" value="Upload"&gt;
  &lt;/form&gt;
  
  foreach($_FILES['files']['name'] as $i =&gt; $name) {
  
   $name = $_FILES['files']['name'][$i];
   $size = $_FILES['files']['size'][$i];
   $type = $_FILES['files']['type'][$i];
   $tmp = $_FILES['files']['tmp_name'][$i];
  
   $explode = explode('.', $name);
  
   $ext = end($explode);
  
   $path = 'uploads/';
   $path = $path . basename( $explode[0] . time() .'.'. $ext);
   
   $errors = array();
  
   if(empty($_FILES['files']['tmp_name'][$i])) {
    $errors[] = 'Please choose at least 1 file to be uploaded.';
   }
   if(empty($errors)) {
    
    if(!file_exists('uploads')) {
     mkdir('uploads', 0777);
    }
  
    if(move_uploaded_file($tmp, $path)) {
     echo '&lt;p&gt;The file &lt;b&gt;'.$name.'&lt;/b&gt; successfully uploaded&lt;/p&gt;';
    }else {
     echo 'Something went wrong while uploading the file &lt;b&gt;'.$name.'&lt;/b&gt;';
    }
  
   }else {
    foreach($errors as $error) {
     echo '&lt;p&gt;'.$error.'&lt;p&gt;';
    }
   }
  
  }
  ?&gt;</code></pre>
  </div>
  </div>
  </p>