Merge branch 'MDL-55513-master' of https://github.com/lucisgit/moodle
authorAndrew Nicols <andrew@nicols.co.uk>
Mon, 15 Aug 2016 06:07:41 +0000 (14:07 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Mon, 15 Aug 2016 06:07:41 +0000 (14:07 +0800)
1  2 
lib/filestorage/file_storage.php

@@@ -354,9 -354,9 +354,9 @@@ class file_storage 
          // Copy the file to the tmp dir.
          $uniqdir = "core_file/conversions/" . uniqid($file->get_id() . "-", true);
          $tmp = make_temp_directory($uniqdir);
 -        $localfilename = $file->get_filename();
 +        $ext = pathinfo($file->get_filename(), PATHINFO_EXTENSION);
          // Safety.
 -        $localfilename = clean_param($localfilename, PARAM_FILE);
 +        $localfilename = $file->get_id() . '.' . $ext;
  
          $filename = $tmp . '/' . $localfilename;
          try {
                  throw new file_exception('storedfileproblem', 'Could not copy file contents to temp file.');
              }
          } catch (file_exception $fe) {
-             remove_dir($uniqdir);
+             remove_dir($tmp);
              throw $fe;
          }
  
          chdir($tmp);
          $result = exec($cmd, $output);
          chdir($currentdir);
-         if (!file_exists($newtmpfile)) {
-             remove_dir($uniqdir);
+         touch($newtmpfile);
+         if (filesize($newtmpfile) === 0) {
+             remove_dir($tmp);
              // Cleanup.
              return false;
          }
  
          $convertedfile = $this->create_file_from_pathname($record, $newtmpfile);
          // Cleanup.
-         remove_dir($uniqdir);
+         remove_dir($tmp);
          return $convertedfile;
      }