• Welcome to the Chevereto user community!

    Here users from all over the world gather around to learn the latest about Chevereto and contribute with ideas to improve the software.

    Please keep in mind:

    • 😌 This community is user driven. Be polite with other users.
    • 👉 Is required to purchase a Chevereto license to participate in this community (doesn't apply to Pre-sales).
    • 💸 Purchase a Pro Subscription to get access to active software support and faster ticket response times.

Periods in filenames cause incomplete name

Status
Not open for further replies.

insomniax

Chevereto Member
I noticed if a file is named with periods in place of spaces the name is shortened to the first period location. Example:

My.Test.Image.png becomes: My.png

Where is the naming code that is causing this?
 
Nevermind, I found it. To anyone else looking it's in class.upload.php

After line 489 which has the following:
PHP:
        $method = (!check_value($method) || !in_array($method, array('original', 'random', 'mixed')) ? 'original' : $method);

Add:
PHP:
        $original_name = preg_replace('/\.+/', '_', substr($original_name,0,strrpos($original_name, ".")));

So your function looks like:
PHP:
    private function nameFile($path='', $extension, $method, $original_name='') {
        $path = trim($path);
        $path = $path == '' ? './' : $path;
        $method = (!check_value($method) || !in_array($method, array('original', 'random', 'mixed')) ? 'original' : $method);
        $original_name = preg_replace('/\.+/', '_', substr($original_name,0,strrpos($original_name, ".")));
        $original_name = !check_value($original_name) ? generateRandomString(rand(5,10)) : preg_replace('/\.(.*)$/', '', $original_name); // Original name as it
        $original_name = preg_replace('/\s+/', '_', $original_name); // Original name with spaces changed to "_"
 
Actually the issue is a regex that is not ok. The problem can be easily fixed by changing the line 490 and 491 with this ones:
PHP:
$original_name = !check_value($original_name) ? generateRandomString(rand(5,10)) : preg_replace('/\.[^.\s]{3,4}$/', '', $original_name); // Original name as it
$original_name = preg_replace('/[\s\.]+/', '_', $original_name); // Original name with spaces and dots changed to "_"
 
Status
Not open for further replies.
Back
Top