Uploaded filenames too long Uploaded filenames too long
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Uploaded filenames too long

Started by artoonie, June 24, 2008, 10:51:21 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

artoonie

I've searched, but couldn't find any direct answers on this, so I thought I'd post my little mod:

Open:
upload.php

Find:

        // Create a unique name for the uploaded file
        $nr = 0;
        $picture_name = $matches[1] . '.' . $matches[2];
        while (file_exists($dest_dir . $picture_name)) {
            $picture_name = $matches[1] . '~' . $nr++ . '.' . $matches[2];
        }


Replace:

        // Create a unique name for the uploaded file
        $nr = 0;
$matches[1] = substr($matches[1],0,15); // If the filename is too long, shorten
        $picture_name = $matches[1] . '.' . $matches[2];
        while (file_exists($dest_dir . $picture_name)) {
            $picture_name = $matches[1] . '~' . $nr++ . '.' . $matches[2];
        }



EOM;







All this does is add the following line:
$matches[1] = substr($matches[1],0,15); // If the filename is too long, shorten
to make the filename a maximum of 15 characters.
I don't know if it's the most efficient way, but it seems to work fine.


It'd be nice if something similar could be included in a future version, perhaps even with a config-option for how the max filename size.







Hope this helps someone out there,
Toonie

artoonie

Note: do this for db_input.php as well, if that file is in use (meaning, if you have the single-upload form enabled).

Joachim Müller

@moderators: do not move this thread to the mods board - it doesn't qualify as real mod.

@artoonie: thanks for your readiness to share. However, you have to make sure that another file with an identical name doesn't already exist. Additionally, coppermine has several methods of uploading, so you're have to take care of this issue in several places.

@Hein: I undid your edit/move. Please don't re-move.

Joachim