Php get file extension from array value
<p>I'm new php, It's learning process.  </p>

<p>I've a html upload form. I'm trying to rename the uploaded file. So Following is php code that get the file extension and after that i add a php  uniqid(); to rename it.  </p>

<p><strong>Get file extension code:</strong></p>

<pre><code>$img = $_FILES['images']['name'];

function getExtension($str)
{
     $i = strrpos($str,".");
     if (!$i) { return ""; } 

     $l = strlen($str) - $i;
     $ext = substr($str,$i+1,$l);
     return $ext;
}

$extension =  getExtension($img);
$id = uniqid();
$newimg = $id.'.'.$extension;
</code></pre>

<p>Well, this OK for me for only one upload file, <strong>BUT</strong> if I've multiple upload form then how do i get multiple files extension with this function?</p>

<p><strong>For get the multiple files following is my php code:</strong></p>

<pre><code>$uploaded_files = array();
$upload_directory = dirname(__file__) . '/uploaded/'; //set upload directory    


for ($i = 0; $i &lt; count($_FILES['images']['name']); $i++)
            {
                $number_of_file_fields++;

                if ($_FILES['images']['name'][$i] != '')
                { //check if file field empty or not
                    $number_of_uploaded_files++;

$uploaded_files[] = $_FILES['images']['name'][$i];

if (move_uploaded_file($_FILES['images']['tmp_name'][$i], $upload_directory .   $_FILES['images']['name'][$i]))
                    {
                        $number_of_moved_files++;
                    }

                }

            }
</code></pre>

<p><strong>Html Form</strong></p>

<pre><code>&lt;table width="1020" border="0" cellspacing="7" cellpadding="0"&gt;   
&lt;tr&gt;
 &lt;td valign="top" width="250"&gt;
     Upload your property picture
 &lt;/td&gt;
 &lt;td&gt;
    &lt;div id="file_container"&gt;
        &lt;input name="images[]" type="file" class="tr2"  /&gt;
        &lt;br /&gt;
    &lt;/div&gt;
 &lt;a href="javascript:void(0);" onClick="add_file_field();"&gt;Add another&lt;/a&gt;
 &lt;input type="submit" value="Save &amp; Continue" name="Submit" class="submit" /&gt;
 &lt;/td&gt;  
&lt;/tr&gt; 
&lt;/table&gt;
</code></pre>
