title: Rename files while uploading with php
body: <p>I have a html form + php for uploading 3 pdfs similarly. while uploading i have to cut the names of the files. For instance instead of AB_2020_02_02.pdf i want to have it changed in AB.pdf - for all three files simultaneously. I tried with <code>rename($original_filename, substr($original_filename, 2) . '.pdf');</code> Any other ideas?
  This is the entire code:</p>
  
  <pre><code>&lt;?php
  // Set Upload Path
  $target_dir = '';
        $_FILES = substr($_FILES, 2, strlen($_FILES) - 12);
  
  if( isset($_FILES['fileUpload']['name'])) {
  
    $total_files = count($_FILES['fileUpload']['name']);
    for($key = 0; $key &lt; $total_files; $key++) {
      // Check if file is selected
      if(isset($_FILES['fileUpload']['name'][$key]) 
                        &amp;&amp; $_FILES['fileUpload']['size'][$key] &gt; 0) {
  
        $original_filename = $_FILES['fileUpload']['name'][$key];
        rename($original_filename, substr($original_filename, 2) . '.pdf');  
      $target = $target_dir . basename($original_filename);
        $tmp  = $_FILES['fileUpload']['tmp_name'][$key];
        move_uploaded_file($tmp, $target);
      }
  
    }
  
  }
  ?&gt;
  </code></pre>