2010-04-12 4 views

답변

0

소스를 보면 모듈이 upload_manager를 사용하여 업로드 된 파일을 처리 할 때 파일 형식을 제한하는 방법이 없습니다. 또한 파일 내용을 기반으로 한 임의의 MIME 유형 감지를 사용하지 않습니다. moodle에있는 filelib 라이브러리는 파일 확장자에서 mimetype을 기반으로합니다.

무들 업로드 관리자 객체를 사용하는 동안 모듈에 대해 이것을 수행하는 깔끔한 방법은 기존 upload_manager 클래스를 확장하는 새로운 클래스를 작성하고 파일 내용을 기반으로 일부 유효성 검증을 추가하는 것입니다.

다음과 같은 사항이 있습니다. 약간 정리하고 인증 코드로 완성해야합니다.

class upload_manager_strict extends upload_manager { 
    var $allowed_types 
    function upload_manager_strict($inputname='', $deleteothers=false, $handlecollisions=false, $course=null, $recoverifmultiple=false, $modbytes=0, $silent=false, $allownull=false, $allownullmultiple=true, $allowed_types=null) { 
    $this->allowed_types = $allowed_types; 
    parent::upload_manager_strict($inputname, $deleteothers, $handlecollisions, $course, $recoverifmultiple, $modbytes, $silent, $allownull, $allownullmultiple) 
    } 

    function validate_file(&$file) { 
    $status = parent::validate_file(&$file); 
    if ($status) { 
     // do some mimetype checking and validation on the file $file['tmp_name'] 
     // could use $this->allowedtypes 
    } 
    return $status; 
    } 
} 
+0

첨부 된 moodle 패치 버그를 제출하셨습니까? 허용 된 파일 목록이 등록 정보/구성 파일에서 읽히거나 관리 GUI를 통해 설정되면 이는 유용한 기능입니다. –

관련 문제