title: Separate new filename and input into database
body: <p>This code work good in making separate name and put their new name into database if the form is full submitted. The error is:</p>
  
  <p>When I submit empty form:</p>
  
  <blockquote>
    <p>Warning: Illegal offset type in C:\xampp\htdocs\cobas\create.php on line 38</p>
    
    <p>Warning: Illegal offset type in C:\xampp\htdocs\cobas\create.php on line 38</p>
  </blockquote>
  
  <p>When I submit which just input file 1 has the photo it says (the photo 1 moved into upload folder):</p>
  
  <blockquote>
    <p>Warning: Illegal offset type in C:\xampp\htdocs\cobas\create.php on line 38</p>
    
    <p>Warning: Illegal offset type in C:\xampp\htdocs\cobas\create.php on line 42</p>
    
    <p>Notice: Undefined offset: 1 in C:\xampp\htdocs\cobas\create.php on line 45</p>
    
    <p>Notice: Undefined offset: 1 in C:\xampp\htdocs\cobas\create.php on line 47</p>
    
    <p>Notice: Undefined index: in C:\xampp\htdocs\cobas\create.php on line 47</p>
    
    <p>Warning: Illegal offset type in C:\xampp\htdocs\cobas\create.php on line 38</p>
  </blockquote>
  
  <p>When I submit which just input file 2 has the photo it says (the photo 2 not moved into upload folder):</p>
  
  <blockquote>
    <p>Warning: Illegal offset type in C:\xampp\htdocs\cobas\create.php on line 38</p>
    
    <p>Warning: Illegal offset type in C:\xampp\htdocs\cobas\create.php on line 38</p>
    
    <p>Warning: Illegal offset type in C:\xampp\htdocs\cobas\create.php on line 42</p>
    
    <p>Notice: Undefined offset: 1 in C:\xampp\htdocs\cobas\create.php on line 45</p>
    
    <p>Warning: move_uploaded_file(): The second argument to copy() function cannot be a directory in C:\xampp\htdocs\cobas\create.php on line 47</p>
    
    <p>Warning: move_uploaded_file(): Unable to move 'C:\xampp\tmp\phpE539.tmp' to 'upload/' in C:\xampp\htdocs\cobas\create.php on line 47</p>
  </blockquote>
  
  <p>When I put submit 2 photo, both is moved into upload folder but still have error:</p>
  
  <blockquote>
    <p>Warning: Illegal offset type in C:\xampp\htdocs\cobas\create.php on line 38</p>
    
    <p>Warning: Illegal offset type in C:\xampp\htdocs\cobas\create.php on line 42</p>
    
    <p>Notice: Undefined offset: 1 in C:\xampp\htdocs\cobas\create.php on line 45</p>
    
    <p>Notice: Undefined offset: 1 in C:\xampp\htdocs\cobas\create.php on line 47</p>
    
    <p>Notice: Undefined index: in C:\xampp\htdocs\cobas\create.php on line 47</p>
    
    <p>Warning: Illegal offset type in C:\xampp\htdocs\cobas\create.php on line 38</p>
    
    <p>Warning: Illegal offset type in C:\xampp\htdocs\cobas\create.php on line 42</p>
  </blockquote>
  
  <p>Here is my code:</p>
  
  <pre><code>define( 'MAX_ALLOWED_FILE_SIZE', 5 * 1024 * 1024 ); // 5Mb
  define( 'UPLOAD_PATH', 'upload' );
  
  function is_allowed_file_ext( $filename = null )
  {
      $allowed_ext = array("jpg", "jpeg", "gif", "png");
      $_parts = explode( '.', $filename );
      $_ext = end( $_parts );
      $_ext = strtolower( $_ext );
      if( in_array( $_ext , $allowed_ext ) ){
          return $_ext;
      }
      return false;
  }
  
  if( !empty( $_FILES['photo'] ) ){
      foreach ($_FILES['photo']['name'] as $key[] =&gt; $filename ) {
          if( $_FILES['photo']['error'][$key] == UPLOAD_ERR_OK ){
  
              if( $file_ext = is_allowed_file_ext( $filename ) ){
                  $new_filename[] = sprintf( '%d-%s.%s', round(microtime(true)), uniqid(), $file_ext );
                  if( $_FILES['photo']['size'][$key] &lt;= MAX_ALLOWED_FILE_SIZE ){
                      // Everything is okay now, save the file                   
                      $dest_path[0] = sprintf( '%s/%s', rtrim(UPLOAD_PATH,'/'), $new_filename[0] );
                      $dest_path[1] = sprintf( '%s/%s', rtrim(UPLOAD_PATH,'/'), $new_filename[1] );                    
                      move_uploaded_file( $_FILES['photo']['tmp_name'][$key[0]], $dest_path[0] );
                      move_uploaded_file( $_FILES['photo']['tmp_name'][$key[1]], $dest_path[1] );
  
                  }else{
                      $photo_errors[] = 'Error: File size is larger than the allowed limit.';
                  }
              }else{
                  $photo_errors[] = $filename . ' is not a valid image';
              }
          }else{
              switch ( $_FILES['photo']['error'][$key] ) {
                  case UPLOAD_ERR_NO_FILE:
                      $photo_errors[] = 'No file sent';
                      break;
                  case UPLOAD_ERR_INI_SIZE:
                  case UPLOAD_ERR_FORM_SIZE:
                      $photo_errors[] = 'Max file size exceeded!';
                      break;
                  default:
                      $photo_errors[] = 'Unknown errors';
                      break;
              }
          }
      }
  }else{
      $photo_errors[] = 'No photos selected';
  }
  
  $sql = "INSERT INTO employees (name, address, salary, code, photo, photo2) VALUES (?, ?, ?, ? , ?, ?)";
  mysqli_stmt_bind_param($stmt, "ssssss", $param_name, $param_address, $param_salary, $asd, $new_filename[0] , $new_filename[1]);
  </code></pre>