Exemple #1
0
$sql .= "AND source_field='attach_type' ";
$sql .= "AND lookup_code = att_type ; ";
$qry = new PgQuery($sql);
if ($qry->Exec("attachment") && $qry->rows > 0) {
    $attachment = $qry->Fetch();
} else {
    $qry = new PgQuery("SELECT * FROM request_attachment WHERE attachment_id = {$id};");
    if (!$qry->Exec("attachment") || $qry->rows == 0) {
        error_log("{$sysabbr} attachment: DBG: id [{$id}] not found", 0);
        echo "<html><head><title>Error - invalid attachment ID [{$id}]</title><body><h1>Invalid attachment ID [{$id}]</h1></body></html>";
        exit;
    }
    $attachment = $qry->Fetch();
    include_once "guess-file-type.php";
    $attachment->lookup_code = guess_file_type($attachment->att_filename, "{$attachment_dir}/{$id}");
    $attachment->lookup_misc = guess_mime_type($attachment->lookup_code);
}
if (!isset($attachment_dir)) {
    $attachment_dir = "attachments";
}
header("Content-type: {$attachment->lookup_misc}");
header("Content-Disposition: filename={$attachment->att_filename}");
$bytes = filesize("{$attachment_dir}/{$id}");
header("Content-length: {$bytes}");
// dump the file
$fp = fopen("{$attachment_dir}/{$id}", 'rb');
fpassthru($fp);
error_log("{$sysabbr} attachment: DBG: Served '{$attachment->att_filename}' as '{$attachment->lookup_misc}' ({$attachment->lookup_code}), {$bytes} bytes");
if ($debuglevel > 1) {
    $total_query_time = sprintf("%3.06lf", $total_query_time);
    $total_time = sprintf("%3.06lf", duration($begin_processing, microtime()));
    $getFiles = $xisDBH->query('SELECT file_id, usr_id, file_name, file_code, file_fld_id, file_views AS file_downloads, file_size, file_ip, file_last_view AS file_last_download, file_created, srv_id FROM Files');
    $success = 0;
    $error = 0;
    $fileMoveErrors = array();
    while ($row = $getFiles->fetch()) {
        $dbFileStorageValue = $row['file_code'];
        // apprend file path
        if ((int) XIMAGESHARING_FOLDER_GROUPING > 0) {
            $actualFolderId = floor((int) $row['file_id'] / 5000);
            $formattedFolderId = str_pad($actualFolderId, 5, "0", STR_PAD_LEFT);
            $dbFileStorageValue = $formattedFolderId . '/' . $dbFileStorageValue;
        }
        // insert into Reservo db
        $sql = "INSERT INTO file (id, originalFilename, shortUrl, fileType, extension, fileSize, localFilePath, userId, totalDownload, uploadedIP, uploadedDate, statusId, visits, lastAccessed, deleteHash, folderId, serverId, accessPassword) VALUES (:id, :originalFilename, :shortUrl, :fileType, :extension, :fileSize, :localFilePath, :userId, :totalDownload, :uploadedIP, :uploadedDate, :statusId, :visits, :lastAccessed, :deleteHash, :folderId, :serverId, :accessPassword)";
        $q = $ysDBH->prepare($sql);
        $count = $q->execute(array(':id' => $row['file_id'], ':originalFilename' => $row['file_name'], ':shortUrl' => $row['file_code'], ':fileType' => guess_mime_type($row['file_name']), ':extension' => strtolower(get_file_extension($row['file_name'])), ':fileSize' => $row['file_size'], ':localFilePath' => $dbFileStorageValue, ':userId' => (int) $row['usr_id'] == 0 ? 'null' : $row['usr_id'], ':totalDownload' => $row['file_downloads'], ':uploadedIP' => long2Ip32bit($row['file_ip']), ':uploadedDate' => $row['file_created'], ':statusId' => 1, ':visits' => $row['file_downloads'], ':lastAccessed' => $row['file_last_download'], ':deleteHash' => MD5($row['file_id'] . rand(10000, 99999) . $row['file_created']), ':folderId' => $row['file_fld_id'], ':serverId' => $row['srv_id'], ':accessPassword' => null));
        if ($count) {
            $success++;
        } else {
            $error++;
        }
    }
    ?>
                            <tr>
                                <td>Files:</td>
                                <td><?php 
    echo $xfsStats['totalFiles'];
    ?>
</td>
                                <td>file:</td>
                                <td><?php 
Exemple #3
0
    // following lines would indicate how the client should handle the cache
    /* $max_age=300;
      $http_headers[] = 'Expires: '.gmdate('D, d M Y H:i:s', time()+$max_age).' GMT';
      // HTTP/1.1 only
      $http_headers[] = 'Cache-Control: private, must-revalidate, max-age='.$max_age;*/
    if ('f' != $_GET['part'] and isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
        set_status_header(304);
        foreach ($http_headers as $header) {
            header($header);
        }
        exit;
    }
}
if (!isset($ctype)) {
    // give it a guess
    $ctype = guess_mime_type(get_extension($file));
}
$http_headers[] = 'Content-Type: ' . $ctype;
if (isset($_GET['download'])) {
    $http_headers[] = 'Content-Disposition: attachment; filename="' . $element_info['file'] . '";';
    $http_headers[] = 'Content-Transfer-Encoding: binary';
} else {
    $http_headers[] = 'Content-Disposition: inline; filename="' . basename($file) . '";';
}
foreach ($http_headers as $header) {
    header($header);
}
// Looking at the safe_mode configuration for execution time
if (ini_get('safe_mode') == 0) {
    @set_time_limit(0);
}