title: how to check post image by id in php
body: <p>I have 3 inputs :</p>
  
  <p><strong>1.</strong> application name</p>
  
  <p><strong>2.</strong> Background photo</p>
  
  <p><strong>3.</strong> logo photo</p>
  
  <p>After I got help from @mith. The code is great. Images always go into correct folder. I adapt the code to change image's name after submit it into folder. But i don't know what wrong with this condition</p>
  
  <pre><code>$fieldname = ($key == 'image[]') ? 'image' : 'logo';
  $filename  = $applicationName . '_' . $fieldname . '.' . 
            pathinfo($upload["tmp_name"], PATHINFO_EXTENSION);
  </code></pre>
  
  <p><code>$filename</code> always be logo. I don't know why the condition always false.
  So, 2 images always named applicationName_logo. please help me find out.</p>
  
  <p><strong>HTML form :</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;form action="yong.php" method="POST" enctype="multipart/form-data"&gt;
      &lt;h3&gt;App name&lt;/h3&gt;
      &lt;input type="text" id="applicationName" name="applicationName"&gt;
      &lt;h3&gt;Background image&lt;/h3&gt;
      &lt;input type="file" id="image" name="image[]" multiple="multiple" accept="image/*" /&gt;
      &lt;h3&gt;Logo image&lt;/h3&gt;
      &lt;input type="file" id="logo" name="logo[]" multiple="multiple" accept="image/*" /&gt;
      &lt;br&gt;
      &lt;br&gt;
      &lt;input type="submit"&gt;
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>PHP code :</p>
  
  <pre><code>    &lt;?php
  $valid_formats = array("jpg", "png", "gif", "zip", "bmp");
  $max_file_size = 5000*100; //100 kb
  $path = "home_dir/"; // Upload directory
  $count = 0;
  
  if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){
  // Loop $_FILES to exeicute all files
  
  $applicationName = $_POST['applicationName'];
  $sql_field_list  = ['applicationName'];
  $sql_value_list  = [$applicationName];
  
  foreach ($_FILES['image']['name'] as $f =&gt; $name) {
      if ($_FILES['image']['error'][$f] == 4) {
          continue; // Skip file if any error found
          echo "Skip file if any error found";
      }
      if ($_FILES['image']['error'][$f] == 0) {
          if ($_FILES['image']['size'][$f] &gt; $max_file_size) {
              $message[] = "$name is too large!.";
              echo "$name is too large!.";
              continue; // Skip large files
          }
          elseif( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats) ){
              $message[] = "$name is not a valid format";
              echo "$name is not a valid format";
              continue; // Skip invalid file formats
          }
          else{ // No error found! Move uploaded files
              $tmp_name  = $upload["tmp_name"];
              $parts     = explode('/', $upload['tmp_name']);
              $tmpName   = array_pop($parts);
              $fieldname = ($key == 'image[]') ? 'image' : 'logo';
              $filename  = $applicationName . '_' . $fieldname . '.' . pathinfo($upload["tmp_name"], PATHINFO_EXTENSION);
          }
  
              //if(move_uploaded_file($_FILES["image"]["tmp_name"][$f], $path.$filename.png))
              if(move_uploaded_file($_FILES["image"]["tmp_name"][$f], $path.'applicationName_bg/'.$filename.png))
                  $count++; // Number of successfully uploaded file
              $message[] = "$name is uploaded";
              echo "$filename is uploaded";
  
      }
  }
  
  foreach ($_FILES['logo']['name'] as $f =&gt; $name) {
      if ($_FILES['logo']['error'][$f] == 4) {
          continue; // Skip file if any error found
          echo "Skip file if any error found";
      }
      if ($_FILES['logo']['error'][$f] == 0) {
          if ($_FILES['logo']['size'][$f] &gt; $max_file_size) {
              $message[] = "$name is too large!.";
              echo "$name is too large!.";
              continue; // Skip large files
          }
          elseif( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats) ){
              $message[] = "$name is not a valid format";
              echo "$name is not a valid format";
              continue; // Skip invalid file formats
          }
          else{ // No error found! Move uploaded files
              $tmp_name  = $upload["tmp_name"];
              $parts     = explode('/', $upload['tmp_name']);
              $tmpName   = array_pop($parts);
              $fieldname = ($key == 'image[]') ? 'image' : 'logo';
              $filename  = $applicationName . '_' . $fieldname . '.' . pathinfo($upload["tmp_name"], PATHINFO_EXTENSION);
          }
  
              //if(move_uploaded_file($_FILES["logo"]["tmp_name"][$f], $path.$filename.png))
              if(move_uploaded_file($_FILES["logo"]["tmp_name"][$f], $path.'applicationName_logo/'.$filename.png))
                  $count++; // Number of successfully uploaded file
              $message[] = "$name is uploaded";
              echo "$filename is uploaded";
  
      }
  }
  }
  </code></pre>