title: How to rename/store images uploaded to e-commerce application?
body: <p>Im writing my first online shop in PHP.  Now working on "add product" form and im not sure know how to store images.</p>
  
  <p>I think i should:</p>
  
  <ol>
  <li>check is this image or not</li>
  <li>resize image to "standard" dimensions used in my shop and generate thumbnail</li>
  <li>generate unique filename and store image in "images" directory</li>
  <li>save image with unique filename and insert row into my Images table</li>
  </ol>
  
  <p>I created table with columns like this:</p>
  
  <ul>
  <li>Id</li>
  <li>Location - url of image - "/0953026326323436324.jpg" for example</li>
  <li>OriginalFilename - original name of file that user was uploading - "myproduct1.jpg" for example</li>
  </ul>
  
  <p>Questions:</p>
  
  <ol>
  <li>Is there any better way to do this?</li>
  <li>Shall i use Id from Images table as unique filename, or shall i stay with generating unique name (by using PHP function)?</li>
  <li>Shall i generate md5 hash and store it in Images table to avoid/handle duplicates?</li>
  </ol>
  
  <p>Edit 2012-03-03: 
  By duplicates I mean files with identical content (but maybe diffrent name).</p>
  
  <p>Im not using any framework, that will be simple and lightweight online-shop.</p>