title: How to name uploaded files in php to prevent them from being overwritten?
body: <p>I'm trying to add user submitted articles to my website, (only for admins). With each article comes an option to upload up to 3 images. My database is set up like this</p>
  
  <p>Articles</p>
  
  <pre><code>id
  user_id
  title
  body
  date_added
  last_edited
  </code></pre>
  
  <p>Photos</p>
  
  <pre><code>id (auto_increment)
  article_id
  </code></pre>
  
  <p>First I save the article in the database, then I upload the photo (temporarily) then I create a new photo record in the database saving the article_id. Then I rename the uploaded photo to be the same as the primary key of the photo record, and to be a png.</p>
  
  <p><code>$filename = $photo-&gt;id . '.png';</code></p>
  
  <p>I figured this would be a good way to prevent files form being overwritten. This seems flawed to me. Any suggestions on how I should save my records and photos?</p>
  
  <p>Thanks</p>