打开从服务器下载的文件时出错
Error opening downloaded file from server
我希望用户单击并将 .doc 下载到他们想要的任何位置。文件已下载,但当您打开它时,Word 提示:“缺少文件 C:\Users\MyName\style.css。我单击“确定”,然后它显示了一个损坏的 word 文档。
PHP
<?php
function download($pathToFile) {
header('Content-description: File Download');
header('Content-type: application/force-download');
header('Content-transfer-encoding: binary');
header('Content-length: '.filesize($pathToFile));
header('Content-disposition: attachment; filename="'.basename($pathToFile).'"');
readfile($pathToFile);
}
if($_SERVER['REQUEST_METHOD'] == 'POST'){
if(isset($_POST['CVcrono'])){
download('../curriculum-vitae-modelo1-azul.doc');
}
elseif(isset($_POST['CVfun'])){
download('../curriculum-vitae-modelo1b-azul.doc');
}
elseif(isset($_POST['CVcomb'])){
download('../curriculum-vitae-modelo1c-azul.doc');
}
}
?>
HTML
<tr>
<td>
<input class='entButton' type='submit' name='CVcrono' value="Descargar">
</td>
<td>
<input class='entButton' type='submit' name='CVfun' value="Descargar">
</td>
<td>
<input class='entButton' type='submit' name='CVcomb' value="Descargar">
</td>
</tr>
尝试将 header 更改为:
header("Content-type: application/vnd.ms-word");
尝试插入
ob_clean();
ob_flush();
flush();
之前
readfile($pathToFile);
我希望用户单击并将 .doc 下载到他们想要的任何位置。文件已下载,但当您打开它时,Word 提示:“缺少文件 C:\Users\MyName\style.css。我单击“确定”,然后它显示了一个损坏的 word 文档。
PHP
<?php
function download($pathToFile) {
header('Content-description: File Download');
header('Content-type: application/force-download');
header('Content-transfer-encoding: binary');
header('Content-length: '.filesize($pathToFile));
header('Content-disposition: attachment; filename="'.basename($pathToFile).'"');
readfile($pathToFile);
}
if($_SERVER['REQUEST_METHOD'] == 'POST'){
if(isset($_POST['CVcrono'])){
download('../curriculum-vitae-modelo1-azul.doc');
}
elseif(isset($_POST['CVfun'])){
download('../curriculum-vitae-modelo1b-azul.doc');
}
elseif(isset($_POST['CVcomb'])){
download('../curriculum-vitae-modelo1c-azul.doc');
}
}
?>
HTML
<tr>
<td>
<input class='entButton' type='submit' name='CVcrono' value="Descargar">
</td>
<td>
<input class='entButton' type='submit' name='CVfun' value="Descargar">
</td>
<td>
<input class='entButton' type='submit' name='CVcomb' value="Descargar">
</td>
</tr>
尝试将 header 更改为:
header("Content-type: application/vnd.ms-word");
尝试插入
ob_clean();
ob_flush();
flush();
之前
readfile($pathToFile);