How to overwrite a file upload so that the filename is always the same? I am trying to implement a file upload form in which files are saved. I had written the following code 

&lt;?php

/**
 * @file
 * Contains \Drupal\avenue_product_import\Form\avenue_product_importForm.
 */

namespace Drupal\avenue_product_import\Form;

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\file\Entity\File;

class AvenueForm extends FormBase {

  public function getFormId() {
    return 'AvenueForm';
  }


  public function buildForm(array $form, FormStateInterface $form_state) {

    $form['description'] = [
      '#markup' =&gt; '&lt;p&gt;Use this form to upload a CSV file of Data&lt;/p&gt;',
    ];

    $form['import_csv'] = [
      '#type'              =&gt; 'managed_file',
      '#title'             =&gt; t('Upload file here'),
      '#upload_location'   =&gt; 'public://importcsv/',
      '#default_value'     =&gt; '',
      "#upload_validators" =&gt; ["file_validate_extensions" =&gt; ["csv"]],
      '#states'            =&gt; [
        'visible' =&gt; [
          ':input[name="File_type"]' =&gt; ['value' =&gt; t('Upload Your File')],
        ],
      ],
    ];

    $form['actions']['#type'] = 'actions';


    $form['actions']['submit'] = [
      '#type'        =&gt; 'submit',
      '#value'       =&gt; $this-&gt;t('Upload CSV'),
      '#button_type' =&gt; 'primary',
    ];

    return $form;
  }

  public function submitForm(array &amp;$form, FormStateInterface $form_state) {

    /* Fetch the array of the file stored temporarily in database */
    $csv_file = $form_state-&gt;getValue('import_csv');

    /* Load the object of the file by it's fid */
    $file = File::load($csv_file[0]);

    /* Set the status flag permanent of the file object */
    $file-&gt;setPermanent();

    /* Save the file in database */
    $file-&gt;save();

    drupal_set_message('File Uploaded Successfully');
  }

}


But here the problem is if the filename in which I am uploading is same. It is getting renamed. But I want to replace old with the new one. How can I achieve this? I had seen file_move() and file_save_upload() function. What changes should I make to replace existing filename with the newly uploaded CSV file?
This would save always save the latest upload to public://importcsv/avenue.csv:

public function submitForm(array &amp;$form, FormStateInterface $form_state) {

  /* Fetch the array of the file stored temporarily in database */
  $csv_file = $form_state-&gt;getValue('import_csv');

  /* Load the object of the file by it's fid */
  $file = File::load($csv_file[0]);

  $file_real_path = \Drupal::service('file_system')-&gt;realpath($csv_file-&gt;getFileUri());
  $file_contents = file_get_contents($file_real_path);
  file_unmanaged_save_data($file_contents, 'public://importcsv/avenue.csv', FILE_EXISTS_REPLACE);

  drupal_set_message('File Uploaded Successfully');
}