CiviCRM should find proper file id based on file name in case sensitivity mode
Overview
Uploading images via webform to File
custom field causes invalid preview for files with similar names like picture.jpg and Picture.JPG
Reproduction steps
- create webform for creating contacts with image on
File
custom field - fill out the form with image named Picture.JPG (first contact)
- fill out again the form with other image similar named picture.jpg (secord contact)
- open the first contact -> Picture.JPG is on display of custom field
- open the second contact -> Picture.JPG is on display of custom field but should be picture.jpg
Current behaviour
- from unix server perspective files picture.jpg and Picture.JPG are different - this is fine
- from
CRM_Core_DAO::getFieldValue('CRM_Core_DAO_File', $value, 'id', 'uri');
civicrm method Picture.JPG is equal picture.jpg because DB_DataObject package doesn't useBINARY
for conditions
case 'File':
// In the context of displaying a profile, show file/image
if ($value) {
if ($entityId) {
if (CRM_Utils_Rule::positiveInteger($value)) {
$fileId = $value;
}
else {
$fileId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_File', $value, 'id', 'uri');
}
Expected behaviour
CiviCRM should find proper file id based on file name in case sensitivity mode https://dev.mysql.com/doc/refman/5.7/en/case-sensitivity.html
Environment information
- CiviCRM: Master/5.35
- PHP: 7.3_
- CMS: Drupal 7
- Database: 5.7.35-38-log Percona Server
- Web Server: Apache 2.4
Comments
simple workaround
// $fileId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_File', $value, 'id', 'uri');
$query = "SELECT id FROM civicrm_file WHERE uri = BINARY %1";
$params = [
1 => [$value, 'String'],
];
$fileId = (int) CRM_Core_DAO::singleValueQuery($query, $params);