title: Create a unique name for the uploaded image
body: <p>I have a certain code for image upload .I found this on the internet and there was no explanation of the code either.What i can understand from the code is that php upload a certain file makes it a temporary file and then moves the temporary file to the original location</p>
  
  <p>Code Looks something like this </p>
  
  <pre><code> $filename = $_FILES["img"]["tmp_name"];
            list($width, $height) = getimagesize( $filename );
  
  
            move_uploaded_file($filename,  $imagePath . $_FILES["img"]["name"]);
  </code></pre>
  
  <p>What happens now is that when i try to provide an unique name to the image when it is being moved using the <code>move_uploaded_file</code> then a file does come up inside the folder but it says an invalid file and with the extension type of <code>file</code>.
  My code for trying to achieve the same but with an unique name/id for the uploaded image.</p>
  
  <pre><code>$uniquesavename=time().uniqid(rand());
  $filename = $_FILES["img"]["tmp_name"];
        list($width, $height) = getimagesize( $filename );
        move_uploaded_file($filename,  $imagePath . $uniquesavename);
  </code></pre>
  
  <p>How to achieve the same as before and could you please explain me the previous code as well?</p>