$courseid = optional_param('id', 0, PARAM_INT);
$contextid = optional_param('contextid', SYSCONTEXTID, PARAM_INT);
- $filearea = optional_param('filearea', '', PARAM_SAFEDIR);
+ $filearea = optional_param('filearea', '', PARAM_ALPHAEXT);
$itemid = optional_param('itemid', -1, PARAM_INT);
$filepath = optional_param('filepath', '', PARAM_PATH);
$filename = optional_param('filename', '', PARAM_FILE);
throw new file_exception('localfilecannotcreatefiledirs'); // permission trouble
}
// place warning file in file pool root
- $fp = fopen($this->filedir.'/warning.txt', 'w');
- fwrite($fp, 'This directory contains the content of uploaded files and is controlled by Moodle code. Do not manually move, change or rename any of the files and subdirectories here.');
- fclose($fp);
- unset($fp);
+ file_put_contents($this->filedir.'/warning.txt',
+ 'This directory contains the content of uploaded files and is controlled by Moodle code. Do not manually move, change or rename any of the files and subdirectories here.');
}
}
throw new file_exception('localfileproblem', 'Invalid contextid');
}
- $filearea = clean_param($filearea, PARAM_SAFEDIR);
+ $filearea = clean_param($filearea, PARAM_ALPHAEXT);
if ($filearea === '') {
throw new file_exception('localfileproblem', 'Invalid filearea');
}
}
if ($key == 'filearea') {
- $value = clean_param($value, PARAM_SAFEDIR);
+ $value = clean_param($value, PARAM_ALPHAEXT);
if ($value === '') {
throw new file_exception('localfileproblem', 'Invalid filearea');
}
throw new file_exception('localfileproblem', 'Invalid contextid');
}
- $file_record->filearea = clean_param($file_record->filearea, PARAM_SAFEDIR);
+ $file_record->filearea = clean_param($file_record->filearea, PARAM_ALPHAEXT);
if ($file_record->filearea === '') {
throw new file_exception('localfileproblem', 'Invalid filearea');
}
throw new file_exception('localfileproblem', 'Invalid contextid');
}
- $file_record->filearea = clean_param($file_record->filearea, PARAM_SAFEDIR);
+ $file_record->filearea = clean_param($file_record->filearea, PARAM_ALPHAEXT);
if ($file_record->filearea === '') {
throw new file_exception('localfileproblem', 'Invalid filearea');
}
}
$newfile = true;
- $fs = fopen($pathname, 'rb');
- $fp = fopen($hashfile, 'wb');
- while(!feof($fs)) {
- $buf = fread($fs, 65536);
- if ($buf === false) {
- throw new file_exception('localfilecannotread');
- }
- fwrite($fp, $buf);
+ if (!copy($pathname, $hashfile)) {
+ throw new file_exception('localfilecannotread');
}
- fclose($fp);
- fclose($fs);
if (filesize($hashfile) !== $filesize) {
@unlink($hashfile);
}
$newfile = true;
- $fp = fopen($hashfile, 'wb');
-
- fwrite($fp, $content);
- fclose($fp);
+ file_put_contents($hashfile, $content);
if (filesize($hashfile) !== $filesize) {
@unlink($hashfile);
}
/**
- * Protected - devs must not gain direct access to this function
+ * Protected - developers must not gain direct access to this function
**/
protected function get_content_file_location() {
// NOTE: do not make this public, we must not modify or delete the pool files directly! ;-)
return file_get_contents($this->get_content_file_location());
}
+ /**
+ * Copy content of file to give npathname
+ * @param string $pathnema rela path to new file
+ * @return bool success
+ */
+ public function copy_content_to($pathname) {
+ $path = $this->get_content_file_location();
+ if (!is_readable($path)) {
+ throw new file_exception('localfilecannotread');
+ }
+ return copy($path, $pathname);
+ }
+
public function get_contextid() {
return $this->file_record->contextid;
}
public function get_timemodified() {
return $this->file_record->timemodified;
}
+
+ public function get_status() {
+ return $this->file_record->status;
+ }
}
require_once("$CFG->libdir/file/file_exceptions.php");
require_once("$CFG->libdir/file/file_storage.php");
require_once("$CFG->libdir/file/file_browser.php");
+require_once("$CFG->libdir/file/file_packer.php");
function get_file_url($path, $options=null, $type='coursefile') {
global $CFG;
return false;
}
}
- if (!$temp = @fopen($_FILES[$elname]['tmp_name'], "rb")) {
- return false;
- }
- if (!$file = @fopen($pathname, "wb")) {
+ if (!copy($_FILES[$elname]['tmp_name'], $pathname)) {
return false;
}
- while (!feof($temp)) {
- $data = fread($temp, 65536);
- fwrite($file, $data);
- }
- fclose($file);
- fclose($temp);
-
return true;
}
return false;
}
- if (!$file = @fopen($_FILES[$elname]['tmp_name'], "rb")) {
- return false;
- }
-
- $data = '';
- while (!feof($file)) {
- $data .= fread($file, 4048);
- }
- fclose($file);
-
- return $data;
+ return file_get_contents($_FILES[$elname]['tmp_name']);
}
/**
return $fb;
}
+/**
+ * Returns local file storage instance
+ * @return object file_storage
+ */
+function get_file_packer() {
+ global $CFG;
+
+ static $fp = null;
+
+ if ($fp) {
+ return $fp;
+ }
+
+ require_once("$CFG->libdir/filelib.php");
+
+ $fp = new file_packer();
+
+ return $fp;
+}
+
/**
* Makes an upload directory for a particular module.
*