Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-11586

Upload manager file naming error when file does not have extension

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.7, 1.7.1, 1.7.2, 1.8, 1.8.1, 1.8.2, 1.9
    • Fix Version/s: 1.9
    • Component/s: Other
    • Labels:
      None
    • Affected Branches:
      MOODLE_17_STABLE, MOODLE_18_STABLE, MOODLE_19_STABLE
    • Fixed Branches:
      MOODLE_19_STABLE

      Description

      In the uploadlib.php file, the is a function handle_filename_collision.

      When you have a file called "myfile" without an extention, and that file already exist, it will create the next filename as "_1.myfile" instead of myfile_1.

      I have done some changes to the code and it here is it. Please let me kno when it is fixed in the library.

      Fix:
      --------
      function handle_filename_collision($destination, &$file, $format='%s_%d.%s') {
      $part1 = explode('.', $file['name']);

      $numparts = count($part1);

      $bits = array();
      if ($numparts == 1)

      { $bits[0] = array_pop($part1); $bits[1] = ''; }

      else

      { $bits[1] = array_pop($part1); $bits[0] = implode('.', $part1); }

      // check for collisions and append a nice numberydoo.
      if (file_exists($destination .'/'. $file['name'])) {
      $a->oldname = $file['name'];
      for ($i = 1; true; $i++) {
      $try = sprintf($format, $bits[0], $i, $bits[1]);
      if (eregi("\.$", $try ) )

      { $try = substr($try, 0, strlen($try)-1); }

      if ($this->check_before_renaming($destination, $try, $file))

      { $file['name'] = $try; break; }

      }
      $a->newname = $file['name'];
      $file['uploadlog'] .= "\n". get_string('uploadrenamedcollision','moodle', $a);
      }
      }
      -------

        Attachments

          Activity

            People

            Assignee:
            skodak Petr Skoda
            Reporter:
            bazaar Mawuli Kuivi
            Tester:
            Nobody Nobody
            Participants:
            Component watchers:
            Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias, Sujith Haridasan
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              3/Mar/08