From f95ca5ff41a3dabda08070c25baab2a70fdc9894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Carlos=20Ra=C3=B1a?= Date: Tue, 31 Jul 2012 19:07:17 +0200 Subject: [PATCH] Feature #4856 check if there is avalaible enought space in course folder --- main/inc/lib/jpegcam/webcam_receiver.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/main/inc/lib/jpegcam/webcam_receiver.php b/main/inc/lib/jpegcam/webcam_receiver.php index 1c259abc8e..01bc173e07 100644 --- a/main/inc/lib/jpegcam/webcam_receiver.php +++ b/main/inc/lib/jpegcam/webcam_receiver.php @@ -75,13 +75,28 @@ if (!$content) { exit(); } + +//make a temporal file for get the file size + +$tmpfname = tempnam("/tmp", "CTF"); +$handle = fopen($tmpfname, "w"); +fwrite($handle, $content); +fclose($handle); + +// Check if there is enough space in the course to save the file +if (!DocumentManager::enough_space(filesize($tmpfname), DocumentManager::get_course_quota())) { + unlink($tmpfname); + die(get_lang('UplNotEnoughSpace')); +} + +//erase temporal file +unlink($tmpfname); + //add to disk $fh = fopen($documentPath, 'w') or die("can't open file"); fwrite($fh, $content); fclose($fh); - -// //add document to database $doc_id = add_document($_course, $webcamdir.'/'.$webcamname_to_save, 'file', filesize($documentPath), $title_to_save); api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], $groupId, null, null, null, $current_session_id);