title: php how to change file name when being uploaded
body: <p>I have this code</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;?php //  display  file  upload  form
  if  (!isset($_POST['submit']))  { ?&gt;
  &lt;form enctype="multipart/form-data" action="&lt;?php echo $_SERVER['PHP_SELF']?&gt;" method="post"&gt;
  
  &lt;input type="hidden" name="MAX_FILE_SIZE" value="8000000" /&gt; Select file:
  
  &lt;input type="file" name="data" /&gt;
  
  &lt;input type="submit" name="submit" value="Upload  File" /&gt;&lt;/form&gt;
  
  &lt;?php
  }  else  {
  //  check  uploaded  file  size
  if  ($_FILES['data']['size']  ==  0)  {
  die("ERROR:  Zero  byte  file  upload");
  } //  check  if  this  is  a  valid  upload
  if  (!is_uploaded_file($_FILES['data']['tmp_name']))   {
  die("ERROR:  Not  a  valid  file  upload"); } //  set  the  name  of  the  target  directory
  $uploadDir  =  "./uploads/"; //  copy  the  uploaded  file  to  the  directory
  move_uploaded_file($_FILES['data']['tmp_name'],  $uploadDir  .  $_FILES['data']['name'])  or  die("Cannot  copy  uploaded  file"); //  display  success  message
  echo  '&lt;p style="text-align: center"&gt;
  Soubor byl úspěšně nahrán na server. &lt;br&gt;
  &lt;a href="index.php" class="button1"&gt;Zpět&lt;/a&gt;
  &lt;/p&gt;
  
  ' ; } ?&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>And I have a problem - it works, uploads the file to server but if there is a break in the file name, I cannot download it. e.g I want to upload "my salary únor.pdf", but the server keeps looking for file "my". Is there a way to modify this code to change the breaks in the file name to "_"? Also I would like the server to be in utf-8 letter (as the server changes the file name to silly names e.g. u?nor) So if there is a option for that too that would be great. (or just let php change the file name inty "my_salary_unor" Thank you all for your help ad sugestions.</p>