This is a follow on from How can I control the filenames of files uploaded via SAEF/Safecracker using Safecracker File in a Matrix? but is a different topic so I thought I should start a new question for future reference.

I have a Matrix field that contains a SafeCracker File field.

Images are uploaded to this field.

It appears that if I upload 2 images with filenames that are the same, but of different case, such as TEST.jpg and test.jpg then both images upload fine.

In the back end, on the entry form, the Matrix is displayed correctly with each image being shown.

However, when outputting the images on the front end the case of the file gets mixed up and I would see test.jpg output twice. The other file TEST.jpg is ignored.

Here is my test code. My Matrix field is called {photos} the Safecracker field within that is called {file}

 <p>Row: {row_id}</p>
 <p>File: {file}</p>

Using the example files above I would expect to see.

Row: 1
File: /images/test.jpg
Row 2
File: /images/TEST.jpg

But in fact I see

Row: 1
File: /images/test.jpg
Row 2
File: /images/test.jpg

Since my server is case sensitive it is possible for both of these files to exist so it's causing a problem when the images are being output and the incorrect image is being shown in some cases.

Is anyone able to shed some light on this or try it out themselves to confirm the problem?

2 Answers 2


I ran into the same issue - after a bit of a hunt, I found where the file value was being pulled from - a database query in system/expressionengine/models/file_model.php

That search wasn't case-sensitive, so I guess it was grabbing the first match it found.

My somewhat hacky solution was to change file_model.php around line 334 and update the get_files_by_name function to the following:

function get_files_by_name($file_name, $dir_id)
        if (empty($file_name) OR empty($dir_id))
            return FALSE;
        //$this->db->save_queries = true;
        $dir_func = $this->_where_function($dir_id);
        $name_func = $this->_where_function($file_name);

        $this->db->$dir_func('upload_location_id', $dir_id);

        if (is_array($file_name))
            $this->db->where_in('file_name', $file_name);
            $this->db->where('file_name = "'.$file_name.'" COLLATE utf8_bin', NULL, FALSE);

        $query = $this->db->get('files');
        return $query;      


I'm not sure if this adversely affects security or other file things, but so far seems to be doing the trick for me.

I posted a bug report here

  • Thanks! I'll take a look at that. I've sort of worked around it for the moment but could probably do with applying some kind of 'patch' for it - I can see the same issue arising in future.
    – foamcow
    Jun 27, 2013 at 9:27
  • Mind me asking what your workaround was? Did you manage to give your files unique names in the end?
    – Tim Jukes
    Jun 27, 2013 at 13:41
  • Not so much a workaround as an issue that would not normally arise. Users are uploading their own images - if a similar name exists the file they upload is renamed. However, there are some files that were dropped into the folder manually and it's these that cause the problem. Now I think of it, perhaps the problem is that these aren't indexed so no renaming occurs when an image is uploaded.
    – foamcow
    Jun 27, 2013 at 14:59

Just wanted to update this question if anyone else experiences it. There's a solution posted in the Bug Tracker here: https://support.ellislab.com/bugs/detail/19512.

EDIT: The following actually broke all my uploaded images on EE 2.5.2, so perhaps it works for 2.6.1, but NOT 2.5.2. Proceed with caution.

But... if it's too much hassle to log in, here it is :-)

In system/expressionengine/models/file_model.php, around line 345 change

->$name_func('file_name', $file_name)


->$name_func('file_name', $file_name.' COLLATE latin1_general_cs', TRUE)

Hope that helps someone out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.