View Single Post
Old 10-25-2007, 09:04 PM   #5 (permalink)
Shane
The Visitor
 
Join Date: Oct 2007
Posts: 4
Thanks: 0
Shane is on a distinguished road
Default

Code:
define('DIRECTORY', 'images/');
function getImageName($szImage)
{
$filename =  getImageName($_FILES['filetoupload']['name']);
    $iIndex = 2;
    
    if(!file_exists(DIRECTORY . $szImage))
    {
        return $szImage;
    }
    
    $aParts = explode('.', $szImage);
    
    if(count($aParts) <= 1)
    {
        return $szImage;
    }
    
    $szExt = end($aParts);
    $iCount = count($aParts);
    
    $aParts[$iCount - 1] = $iIndex;
    $aParts[$iCount] = $szExt;
    
    do { $aParts[count($aParts) - 2] = $iIndex++; }
    while(file_exists(DIRECTORY . implode('.', $aParts)));
    
    return implode('.', $aParts);
}
Shane is offline  
Reply With Quote