Part of the EllisLab Network
   
 
Image Library doesn’t handle filenames withtout extensions properly
Posted: 18 February 2007 10:30 PM   [ Ignore ]  
Summer Student
Total Posts:  7
Joined  01-16-2007

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;
}

Profile
 
 
Posted: 02 March 2007 12:53 AM   [ Ignore ]   [ # 1 ]  
Summer Student
Total Posts:  7
Joined  01-16-2007

I take it nobody cares to even respond to this issue?

Profile
 
 
Posted: 02 March 2007 04:30 AM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  351
Joined  07-25-2006

To be honest, Image_lib would fail in other places without a proper extension. You should be storing the images as $id.jpg at the very least. However, I do agree that said function is overly complex and should be rewritten.

 Signature 

me and some random code, hosted by dh. and a blog too! ++ dead bugs

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 66427 Total Logged-in Users: 36
Total Topics: 84790 Total Anonymous Users: 3
Total Replies: 455008 Total Guests: 239
Total Posts: 539798    
Members ( View Memberlist )
Newest Members:  llogocsaturkeyPeter BryanttherendStudioGeorgiaJZeerfedegheEdgedcenticeRoger_Mx