#89 Copy files to temp directory before accessing

This commit is contained in:
Andrew Nicols 2017-03-08 14:30:34 +08:00
parent f83e3dca58
commit 10310523c6
3 changed files with 6 additions and 16 deletions

View file

@ -84,8 +84,6 @@ class element extends \customcertelement_image\element {
* @param \stdClass $user the user we are rendering this for
*/
public function render($pdf, $preview, $user) {
global $CFG;
// If there is no element data, we have nothing to display.
if (empty($this->element->data)) {
return;
@ -96,10 +94,8 @@ class element extends \customcertelement_image\element {
// Get the image.
$fs = get_file_storage();
if ($file = $fs->get_file_by_hash($imageinfo->pathnamehash)) {
$contenthash = $file->get_contenthash();
$l1 = $contenthash[0] . $contenthash[1];
$l2 = $contenthash[2] . $contenthash[3];
$location = $CFG->dataroot . '/filedir' . '/' . $l1 . '/' . $l2 . '/' . $contenthash;
$location = make_request_directory() . '/target';
$file->copy_content_to($location);
// Set the image to the size of the PDF page.
$pdf->Image($location, 0, 0, $pdf->getPageWidth(), $pdf->getPageHeight());

View file

@ -161,8 +161,6 @@ class element extends \mod_customcert\element {
* @param \stdClass $user the user we are rendering this for
*/
public function render($pdf, $preview, $user) {
global $CFG;
// If there is no element data, we have nothing to display.
if (empty($this->element->data)) {
return;
@ -173,10 +171,8 @@ class element extends \mod_customcert\element {
// Get the image.
$fs = get_file_storage();
if ($file = $fs->get_file_by_hash($imageinfo->pathnamehash)) {
$contenthash = $file->get_contenthash();
$l1 = $contenthash[0] . $contenthash[1];
$l2 = $contenthash[2] . $contenthash[3];
$location = $CFG->dataroot . '/filedir' . '/' . $l1 . '/' . $l2 . '/' . $contenthash;
$location = make_request_directory() . '/target';
$file->copy_content_to($location);
$pdf->Image($location, $this->element->posx, $this->element->posy, $imageinfo->width, $imageinfo->height);
}
}

View file

@ -136,10 +136,8 @@ class element extends \mod_customcert\element {
// Show image if we found one.
if ($file) {
$contenthash = $file->get_contenthash();
$l1 = $contenthash[0] . $contenthash[1];
$l2 = $contenthash[2] . $contenthash[3];
$location = $CFG->dataroot . '/filedir/' . $l1 . '/' . $l2 . '/' . $contenthash;
$location = make_request_directory() . '/target';
$file->copy_content_to($location);
$pdf->Image($location, $this->element->posx, $this->element->posy, $imageinfo->width, $imageinfo->height);
} else if ($preview) { // Can't find an image, but we are in preview mode then display default pic.
$location = $CFG->dirroot . '/pix/u/f1.png';