-
Bug
-
Resolution: Fixed
-
Blocker
-
2.1, 2.2
-
MOODLE_21_STABLE, MOODLE_22_STABLE
-
MOODLE_21_STABLE, MOODLE_22_STABLE, MOODLE_23_STABLE
-
git@github.com:dongsheng/moodle.git
-
MDL-27125_master_2 -
Easy
-
Here is the code for get_file() method for repository class in repository/lib.php:
public function get_file($url, $filename = '') {
|
global $CFG;
|
$path = $this->prepare_file($filename);
|
$fp = fopen($path, 'w');
|
$c = new curl;
|
$c->download(array(array('url'=>$url, 'file'=>$fp)));
|
return array('path'=>$path, 'url'=>$url);
|
}
|
Notice that the file is opened but not closed in this function. This will cause that within the request, after calling this function not whole file may be flushed to the disk. We have tested it on linux and were getting different results, but very often a partial file would be copied from temp/downloads area into the filestorage. The fix is very simple - adding fclose($fp) fixes the issue:
public function get_file($url, $filename = '') {
|
global $CFG;
|
$path = $this->prepare_file($filename);
|
$fp = fopen($path, 'w');
|
$c = new curl;
|
$c->download(array(array('url'=>$url, 'file'=>$fp)));
|
fclose($fp);
|
return array('path'=>$path, 'url'=>$url);
|
}
|
- has been marked as being related by
-
MDL-31925 File Attachments Downloaded From Assignment Submissions Corrupt
-
- Closed
-