protected function _checkName($n) { $Result = parent::_checkName($n); $Extension = pathinfo($Result, 4); $Name = pathinfo($Result, 8); $Result = Gdn_Format::Clean($Name) . '.' . Gdn_Format::Clean($Extension); $Result = trim($Result, '.'); return $Result; }
function GenerateCleanTargetName($TargetFolder, $Name, $Extension = '', $TempFile = False, $bForceOverwriteExisting = False) { if ($Extension == '') { $Extension = pathinfo($Name, 4); $Name = pathinfo($Name, 8); } $Extension = Gdn_Format::Clean($Extension); $BaseName = Gdn_Format::Clean($Name); // check for file with same name $TestName = $BaseName; $TargetFile = $TargetFolder . DS . $TestName . '.' . $Extension; if (!file_exists($TargetFile)) { return $TargetFile; } $IsSameFile = $TempFile != False && file_exists($TempFile) && Crc32File($TempFile) == Crc32File($TargetFile); if ($IsSameFile || $bForceOverwriteExisting) { return $TargetFile; } $Count = 0; $NameSuffix = ''; do { //if (++$Count > 100) $NameSuffix = mt_rand(100, 9999); if (++$Count > 250) { throw new Exception('Cannot generate unique name for file.'); } // make sure that iteration will end $TargetFile = $TargetFolder . '/' . $TestName . $NameSuffix . '.' . $Extension; $FileExists = file_exists($TargetFile); if ($FileExists && file_exists($TempFile) && md5_file($TargetFile) == md5_file($TempFile)) { break; } $NameSuffix = '-' . $Count; } while ($FileExists); return $TargetFile; }
/** * CleanupString function from Vanilla I */ function CleanupString($String) { return Gdn_Format::Clean($String); }