I’m storing images as pure ID numbers, as I don’t need the extensions for anything.
If you give a filename of “21” (for example), the function explode_name returns this array:
‘ext’ => “.21”, ‘name’ => ‘’
Which is incorrect, and backwards.
Introducing the second line of the function here fixes the issue:
function explode_name($source_image)
{
$x = explode('.', $source_image);
if (sizeof($x) == 1) return array('name' => $source_image, 'ext' => '');
$ret['ext'] = '.'.end($x);
$name = '';
$ct = count($x)-1;
for ($i = 0; $i < $ct; $i++)
{
$name .= $x[$i];
if ($i < ($ct - 1))
{
$name .= '.';
}
}
$ret['name'] = $name;
return $ret;
}
This function seems quite unnecessarily complex, also. Here is a much simpler version with the exact same functionality:
function explode_name($source_image)
{
$x = explode('.', $source_image);
if (sizeof($x) == 1) return array('name' => $source_image, 'ext' => '');
$ret['ext'] = ".".array_pop($x);
$ret['name'] = implode('.',$x);
return $ret;
}
