dongwang3066 2012-08-21 20:13
浏览 58
已采纳

通过我的网络服务器提供.docx文件在打开时已损坏

i though i found the answer here: Serving .docx files through Php But i am still getting the error that the file is corrupt when trying to download and open a docx server via php Maybe you can see something wrong with my code. The .doc works fine it is the docx that fail.

$parts = pathinfo($doc);
$docFile = $userDocRoot.$doc;
if ( !file_exists($docFile) ){
    throw new Exception("Can not find ".$parts ['basename']." on server");
}
if ( $parts['extension'] == 'docx' ){
    header('Content-type: application/vnd.openxmlformats- officedocument.wordprocessingml.document');
    header('Content-Disposition: attachment; filename="'.$parts['basename'].'"');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    ob_clean();
    flush();
    readfile($docFile);
}else{
   header('Content-type: application/msword');
   header('Content-Disposition: attachment; filename="'.$parts['basename'].'"');
   readfile($docFile);
}
  • 写回答

5条回答 默认 最新

  • douju6542 2012-08-21 20:44
    关注

    The solution for me was to add

     $fsize = filesize($docFile);
     header("Content-Length: ".$fsize);
    

    Thanks for everyones help

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料