Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: Uploaded filenames too long  (Read 2054 times)

0 Members and 1 Guest are viewing this topic.

artoonie

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 66
Uploaded filenames too long
« on: June 24, 2008, 10:51:21 pm »

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:
Code: [Select]
        // 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:
Code: [Select]
        // 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:
Code: [Select]
$matches[1] = substr($matches[1],0,15); // If the filename is too long, shortento 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
Logged

artoonie

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 66
Re: Uploaded filenames too long
« Reply #1 on: June 30, 2008, 09:48:40 am »

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

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: Uploaded filenames too long
« Reply #2 on: June 30, 2008, 04:14:02 pm »

@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
Logged
Pages: [1]   Go Up
 

Page created in 0.017 seconds with 19 queries.