Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP从其他驱动器打开或下载Zip文件_Php - Fatal编程技术网

使用PHP从其他驱动器打开或下载Zip文件

使用PHP从其他驱动器打开或下载Zip文件,php,Php,我想在Chrome/Mozilla浏览器上使用PHP后端从其他驱动器打开或下载zip文件。Zip文件的位置是P:\niks\all Zip Files\Reports\Report 2019年2月1日。Zip $filePath = 'P:\niks\all Zip Files\Reports\Report 01 feb 2019.zip'; header('Content-Description: File Transfer'); header('Content-Type: applicati

我想在Chrome/Mozilla浏览器上使用PHP后端从其他驱动器打开或下载zip文件。Zip文件的位置是
P:\niks\all Zip Files\Reports\Report 2019年2月1日。Zip

$filePath = 'P:\niks\all Zip Files\Reports\Report 01 feb 2019.zip';
header('Content-Description: File Transfer');
header('Content-Type: application/force-download');
header("Content-Disposition: attachment; filename=\"" . basename($filePath) . "\";");
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($filePath));
ob_clean();
flush();
readfile($filePath);
运行此脚本后,Zip文件将下载到下载文件夹中,但不会打开。我的错误就在下面


在谷歌搜索之后,我没有得到任何答案

如果您将HTML与PHP混合使用,或者您的PHP脚本在关闭标记
?>
后可能包含空格,这意味着有东西正随您的zip内容发送到浏览器中,则可能会发生这种情况。因此,在文本编辑器中打开ZIP文件,查看文件开头的内容,与正确的ZIP存档进行比较,然后查看可以转义此字符的位置。并尝试:


1-删除结束标记
?>
,只让打开的标记
看起来您使用的内容类型不正确:

header('Content-Type: application/force-download');
应该是

header('Content-Type: application/zip');


否则,文件传输可能被浏览器解释为非二进制传输(Read:text),文件可能下载不正确

请考虑阅读一些教程,并提供您已经尝试实现的代码示例。因此,您想使用在Web服务器上运行的PHP下载(?)计算机上的一个文件—
P
drive?文件位于P drive中。我想从P盘下载或直接打开它。如果有任何其他方法可以使用web浏览器实现这一点,这将非常有用。这不起作用。每次都会弹出相同的错误。请尝试添加
ob_start()
ob_end_clean()最后,看看php文档:这也不起作用。发生此问题是因为zip文件位于计算机的另一个驱动器中吗?您好,Javier,此解决方案也没有帮助,因为我遇到了相同的错误。有没有其他方法可以做到这一点?是通过Jquery还是使用bach文件?
header('Content-Type: application/zip');
header('Content-Type: application/octet-stream');