Пример #1
0
 /**
  * Add oject container for attached file
  *
  */
 function object_attached_file()
 {
     $attachment = $this->question->getAttachment();
     if (!empty($attachment)) {
         $mimeType = get_mime_on_ext($attachment);
         return '    <object type="' . $mimeType . '" data="' . xmlentities($attachment) . '" />' . "\n";
     }
     return '';
 }
    header('Invalid Argument', true, 400);
    die;
}
$token = $_REQUEST['token'];
$tableName = get_module_main_tbl(array('mobile_tokens'));
$tableName = $tableName['mobile_tokens'];
$sql = 'SELECT * FROM `' . $tableName . '` WHERE token = \'' . claro_sql_escape($token) . '\' AND ADDTIME(`requestTime`,\'0 0:0:30\') > NOW()';
$result = Claroline::getDatabase()->query($sql);
if (!$result->isEmpty()) {
    $row = $result->fetch();
    $pathInfo = $row['requestedPath'];
    $uid = $row['userId'];
    $canRetry = $row['canRetry'];
    $wasFolder = $row['wasFolder'];
    $extension = get_file_extension($pathInfo);
    $mimeType = get_mime_on_ext($pathInfo);
    if ($canRetry) {
        $sql = 'UPDATE `' . $tableName . '` SET `canRetry` = \'0\' WHERE token = \'' . claro_sql_escape($token) . '\'';
        Claroline::getDatabase()->exec($sql);
    }
    if (strtoupper(substr(PHP_OS, 0, 3)) == "WIN") {
        $rootSys = str_replace('//', '/', strtolower(str_replace('\\', '/', $rootSys)));
        $pathInfo = strtolower(str_replace('\\', '/', $pathInfo));
    }
    $document_url = str_replace($rootSys, $urlAppend . '/', $pathInfo);
    if (get_conf('useSendfile', true) && ($mimeType != 'text/html' || $extension == 'url') || $wasFolder) {
        if (claro_send_file($pathInfo) !== false) {
            $claroline->notifier->event('download', array('data' => array('url' => $document_url)));
            if ($wasFolder) {
                unlink($pathInfo);
            }
Пример #3
0
/**
 * Send a stream over HTTP
 * @param   string $stream file stream
 * @param   string $name file name to force (optional)
 * @param   string $mimeType mime type of the stream if none given, the function
 *  will try to guess it from $name
 * @param   string $charset character encoding of the strem, if none given the
 *  function will use the encoding of the current page
 * @return  number of octets sent
 * @since Claroline 1.9.5
 */
function claro_send_stream($stream, $name, $mimeType = null, $charset = null)
{
    $charset = empty($charset) ? '; charset=' . get_locale('charset') : '; charset=' . $charset;
    if (is_null($mimeType)) {
        $mimeType = get_mime_on_ext($name);
    }
    header('Content-Type: ' . $mimeType . $charset);
    // IE no-cache bug
    // TODO move $lifetime to config
    $lifetime = 60;
    header('Cache-Control: max-age=' . $lifetime);
    header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $lifetime) . ' GMT');
    header('Pragma: ');
    // Patch proposed by Diego Conde <*****@*****.**> - Universidade de Vigo
    // It seems that with the combination of OfficeXP and Internet Explorer 6 the
    // downloading of powerpoints fails sometimes. I captured the network packets
    // and the viewer of the office doesn't send all the needed cookies,
    // therefore claroline redirects the viewer to the login page because its not
    // correctly authenticated.
    if (strtolower(pathinfo($name, PATHINFO_EXTENSION)) == "ppt") {
        // force file name for ppt
        header('Content-Disposition: attachment; filename="' . $name . '"');
    } else {
        // force file name for other files
        header('Content-Disposition: inline; filename="' . $name . '"');
    }
    header('Content-Length: ' . strlen($stream));
    echo $stream;
    return strlen($stream);
}