leading accentuated char in directory name #1176

Open
opened 2026-10-05 00:34:32 +02:00 by adam · 2 comments
Owner

Hi,
when adding an accentuated char 'é' in permitted characters, you can import directories and files with this char. Great.

// permitted characters for files/directories during synchronization
$conf['sync_chars_regex'] = '/^[a-zéA-Z0-9-_.]+$/';

There is a remaining problem when this accentuated char is the first one in the name of a directory, because this makes this directory to be imported as a new one everytimes you sync.
The problem is coming from PHP basename function, which depends on locale, and maybe on the system itself. I thought this problem was a poor utf8 support.
https://github.com/Piwigo/Piwigo/blob/1233694048c47910432c3c29b81338fed73516c5/admin/site_update.php#L236

My workaround was simply to replace it with that function, declared before the loop:

function my_utf8_simili_basename($path, $suffix='') {
    $tab = explode('/', rtrim($path, '/'));
    return end($tab);
}

NB: As $suffix is not handled, one may found a much better basename replacement.

Hi, when adding an accentuated char 'é' in permitted characters, you can import directories and files with this char. Great. ``` // permitted characters for files/directories during synchronization $conf['sync_chars_regex'] = '/^[a-zéA-Z0-9-_.]+$/'; ``` There is a remaining problem when this accentuated char is the first one in the name of a directory, because this makes this directory to be imported as a new one everytimes you sync. The problem is coming from PHP basename function, which depends on locale, and maybe on the system itself. I thought this problem was a poor utf8 support. https://github.com/Piwigo/Piwigo/blob/1233694048c47910432c3c29b81338fed73516c5/admin/site_update.php#L236 My workaround was simply to replace it with that function, declared before the loop: ``` function my_utf8_simili_basename($path, $suffix='') { $tab = explode('/', rtrim($path, '/')); return end($tab); } ``` _NB: As $suffix is not handled, one may found a much better basename replacement._ <!-- github-sync-id:819851570 -->
Author
Owner

This mb_basename function is closer to basename function
https://stackoverflow.com/questions/32115609/basename-fail-when-file-name-start-by-an-accent/66438414#66438414

function mb_basename( $path, $suffix='' ) {
    $array = explode( '/', rtrim( $path, '/' ) ) ;
    $basename = end( $array ) ;
    if( ! empty ( $suffix ) ) {
        $slen = strlen ( $suffix ) ;
        if ( substr ( $basename, -$slen, $slen) == $suffix ) {
            $basename = substr ( $basename, 0, -$slen ) ;
        }
    }
    return $basename;
}
This mb_basename function is closer to basename function https://stackoverflow.com/questions/32115609/basename-fail-when-file-name-start-by-an-accent/66438414#66438414 ``` function mb_basename( $path, $suffix='' ) { $array = explode( '/', rtrim( $path, '/' ) ) ; $basename = end( $array ) ; if( ! empty ( $suffix ) ) { $slen = strlen ( $suffix ) ; if ( substr ( $basename, -$slen, $slen) == $suffix ) { $basename = substr ( $basename, 0, -$slen ) ; } } return $basename; } ``` <!-- github-comment-id:788840172 -->
Author
Owner

The problem seems lighter for files starting with an accentuated letter, indeed they are not imported again during following synchronizations. For instance, picture page is only missing the first char in displaying name, picture display is fine.

The problem seems lighter for files starting with an accentuated letter, indeed they are not imported again during following synchronizations. For instance, picture page is only missing the first char in displaying name, picture display is fine. <!-- github-comment-id:788842298 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/Piwigo#1176