Changeset 455


Ignore:
Timestamp:
Apr 13, 2010, 6:27:23 PM (10 years ago)
Author:
zerodeux
Message:

Add a version (-xx) instead of overwriting files. New version_max parameter defaults to 100. Thanks lhaond for patch idea - closes #9

File:
1 edited

Legend:

Unmodified
Added
Removed
  • bearfile/bearfile.php

    r228 r455  
    2121  $bfh = $conf;
    2222  $bfh['upload_max'] = bearfile_upload_max($conf);
     23  if (!isset($bfh['version_max']))
     24    $bfh['version_max'] = 100;
    2325
    2426 
     
    7173  }
    7274
    73   $target = "$folder/$name";
     75  $target0 = trim("$folder/$name", '.');
     76
     77  $target  = $target0;
     78  $try    = 0;
     79  $max    = $bfh['version_max'];
     80  while (file_exists($target)) {
     81    if (++$try > $max) {
     82      $bfh['error'] = "Could not write file, maximum number of versions ($max) reached.";
     83      return $bfh;
     84    }
     85    $target = preg_replace('/(\..+)?$/', "-$try\$1", $target0 , 1);
     86  }
     87
    7488  if ((!move_uploaded_file($up['tmp_name'], $target))) {
    7589    $bfh['error'] = 'Could not write file, please contact your technical support.';
Note: See TracChangeset for help on using the changeset viewer.