2014-02-17 59 views
0

我想下载一个PDF文件:下载大小不指定

$output = RP_MAIN . 'docbook/data/myfile' . $_SESSION["sess_code_user"] . '.pdf'; // this is the pdf file I want to download 
$file_size = filesize($output); 
header("Pragma: public"); 
header("Expires: 0"); 
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
header("Content-type: text/enriched"); 
header("Content-length: $file_size"); 
header('Content-Disposition: attachment; filename="'.'manuel.'. $extension .''.'"'); 
ob_clean(); 
flush(); 
print($output); 
exit(); 

的PDF文件存在于系统中,它具有25 KB的大小。但问题是下载弹出窗口(Internet下载管理器)在大小字段中有一个空白字段。

我的代码有什么问题?我该如何解决这个问题?


编辑: 从一个Ajax调用创建的PDF文件,然后在阿贾克斯则开始下载成功:

var request = $.ajax({ 
     data: donne, 
     type: "POST", 
     url: "<?php echo HTTP_AJAX_TACHE ?>TacheCreerPdfAjax.php" , // this creates the pdf file 
     async: false 
    }); 

    request.done(function() { 
     $('#corps').html(request.responseText); 

     if(fichier == "pdf" || fichier == "rtf") 
      window.location.href = '<?php echo PAGE_TACHE ?>?action=TacheGenererManuelExec&fichier=' + fichier ; // this starts the download 
    ... 
    } 

所以启动下载时,则有一个错误,指出源的格式不是pdf!

回答

0

检查:

$output = RP_MAIN . 'docbook/data/myfile' . $_SESSION["sess_code_user"] . '.pdf';  
if (is_file($output)) { 
    $size = filesize($output); 
    if (function_exists('mime_content_type')) { 
     $type = mime_content_type($output); 
    } elseif (function_exists('finfo_file')) { 
     $info = finfo_open(FILEINFO_MIME); 
     $type = finfo_file($info, $output); 
     finfo_close($info); 
    } 
    if ($type == '') { 
     $type = "application/force-download"; 
    } 
    header("Content-Type: $type"); 
    header("Content-Disposition: attachment; filename=$name"); 
    header("Content-Transfer-Encoding: binary"); 
    header("Content-Length: " . $size); 
    readfile($output); 
    exit; 
} else { 
    return false; 
} 
+0

没有,同样的问题:) – pheromix