title: Renaming jpg file in PHP
body: <p>I have an upload functionality wherein I want to check whether there is a duplicate filename in the database. If there is, I would like to rename the jpg so that the photo to be uploaded will still be uploaded.</p>
  
  <p>Here's the lines of codes that I came up with:</p>
  
  <pre><code>$shuffled = "qwertyuiopasdfghjkZxcvbnm";
  $shuffled = str_shuffle($shuffled); 
  $shuffled = $shuffled.".jpg";
  rename($this-&gt;filename,$shuffled);
  </code></pre>
  
  <p>I am using the shuffle function here to somehow give a random new filename,
  I have tried using some other steps like preg_replace, but the jpg file itself gets corrupted. Any ideas?</p>