public function getVariableFile($variableUri) { //distinguish QTI file from other "file" base type $baseType = $this->getVariableBaseType($variableUri); // https://bugs.php.net/bug.php?id=52623 ; // if the constant for max buffering, mysqlnd or similar driver // is being used without need to adapt buffer size as it is atutomatically adapted for all the data. if (core_kernel_classes_DbWrapper::singleton()->getPlatForm()->getName() == 'mysql') { if (defined("PDO::MYSQL_ATTR_MAX_BUFFER_SIZE")) { $maxBuffer = is_int(ini_get('upload_max_filesize')) ? ini_get('upload_max_filesize') * 1.5 : 10485760; core_kernel_classes_DbWrapper::singleton()->getSchemaManager()->setAttribute(PDO::MYSQL_ATTR_MAX_BUFFER_SIZE, $maxBuffer); } } switch ($baseType) { case "file": $value = base64_decode($this->getVariableValue($variableUri)); common_Logger::i(var_export(strlen($value), true)); $decodedFile = taoResults_helpers_Datatypes::decodeFile($value); common_Logger::i("FileName:"); common_Logger::i(var_export($decodedFile["name"], true)); common_Logger::i("Mime Type:"); common_Logger::i(var_export($decodedFile["mime"], true)); $file = array("data" => $decodedFile["data"], "mimetype" => "Content-type: " . $decodedFile["mime"], "filename" => $decodedFile["name"]); break; default: //legacy files $file = array("data" => base64_decode($this->getVariableValue($variableUri)), "mimetype" => "Content-type: text/xml", "filename" => "trace.xml"); } return $file; }
/** * @dataProvider decodeFileProvider * * @param string $binary * @param array $expected */ public function testDecodeFile($binary, array $expected) { $this->assertEquals($expected, taoResults_helpers_Datatypes::decodeFile($binary)); }