gpt4 book ai didi

php - 无法在 ubuntu 服务器上打开 zip 文件错误

转载 作者:行者123 更新时间:2023-12-04 18:30:05 24 4
gpt4 key购买 nike

我必须一次下载多个 csv 文件。因此,我创建了 zip 文件并将所有 csv 文件放入该 zip 文件中。一切正常,我可以下载我的 zip 文件并在我的本地主机上打开。我用的是windows操作系统。

这是我来自 export_csv.php 的代码.

    for($i=0; $i<$len; $i++) {
$user_id = $array[$i];

#get user name
$name = "...";

#get all day from selected month with holidays
$day_of_month_arr = allDay_of_month($year,$month);

#get user datetime

#prepare start and finish time with holidays and weekend
$result_arr = time_format($result, $day_of_month_arr);

#prepare data as csv format to export as csv
$exp = export($result_arr);

#put each user csv file into 'Report.zip'
#archive all csv file as zip and force download that zip file
$zipname = 'Report.zip';
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
$f = fopen('php://memory', 'w');
$file_name = $name."-".$user_id.".csv";
foreach ($exp as $arr) {
fputcsv($f,$arr);
}
rewind($f);
$zip->addFromString($file_name, stream_get_contents($f));
//close the file
fclose($f);

}

$zip->close();
header('Content-Type: application/zip');
header('Content-disposition: attachment; filename='.$zipname);
header('Content-Length: ' . filesize($zipname));
readfile($zipname);

// remove the zip archive
unlink($zipname);

function export() {.......}
function time_format() {........}
function allDay_of_month() {......}

所以,我上传了那个脚本 export_csv.php到我的 ubuntu 服务器(生产服务器)。当我尝试从生产服务器下载此文件时,我可以下载该文件但无法再打开此 zip 文件。它显示 "......\Report.zip" is invalid" .

当我检查 php_error_logs 中的问题时,我发现了以下问题。
[12-Oct-2016 04:09:43 Europe/Berlin] PHP Warning:  main(): Cannot destroy the zip context in /opt/lampp/htdocs/project/export_csv.php on line 48
[12-Oct-2016 04:09:43 Europe/Berlin] PHP Warning: main(): Cannot destroy the zip context in /opt/lampp/htdocs/project/export_csv.php on line 48
[12-Oct-2016 04:09:43 Europe/Berlin] PHP Warning: main(): Cannot destroy the zip context in /opt/lampp/htdocs/project/export_csv.php on line 48
[12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning: main(): Cannot destroy the zip context in /opt/lampp/htdocs/project/export_csv.php on line 48
[12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning: main(): Cannot destroy the zip context in /opt/lampp/htdocs/project/export_csv.php on line 48
[12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning: main(): Cannot destroy the zip context in /opt/lampp/htdocs/project/export_csv.php on line 48
[12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning: main(): Cannot destroy the zip context in /opt/lampp/htdocs/project/export_csv.php on line 48
[12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning: main(): Cannot destroy the zip context in /opt/lampp/htdocs/project/export_csv.php on line 48
[12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning: main(): Cannot destroy the zip context in /opt/lampp/htdocs/project/export_csv.php on line 48
[12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning: main(): Cannot destroy the zip context in /opt/lampp/htdocs/project/export_csv.php on line 48
[12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning: main(): Cannot destroy the zip context in /opt/lampp/htdocs/project/export_csv.php on line 48
[12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning: main(): Cannot destroy the zip context in /opt/lampp/htdocs/project/export_csv.php on line 48
[12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning: main(): Cannot destroy the zip context in /opt/lampp/htdocs/project/export_csv.php on line 48
[12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning: main(): Cannot destroy the zip context in /opt/lampp/htdocs/project/export_csv.php on line 48
[12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning: main(): Cannot destroy the zip context in /opt/lampp/htdocs/project/export_csv.php on line 48
[12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning: ZipArchive::close(): Failure to create temporary file: Permission denied in /opt/lampp/htdocs/project/export_csv.php on line 62
[12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning: filesize(): stat failed for Report.zip in /opt/lampp/htdocs/project/export_csv.php on line 65
[12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning: readfile(Report.zip): failed to open stream: No such file or directory in /opt/lampp/htdocs/project/export_csv.php on line 66
[12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning: unlink(Report.zip): No such file or directory in /opt/lampp/htdocs/project/export_csv.php on line 69

我认为这个错误是权限问题。但我是 ubuntu 操作系统的新手,所以我不知道如何解决它。

我非常感谢任何帮助。

更新

当我尝试从服务器下载和打开 zip 文件时,我添加了确切的错误。

最佳答案

似乎您的 php 服务器不允许写入您提供的路径。
您需要将运行 php 服务器的用户的写入权限添加到此路径:/opt/lampp/htdocs/project/

您应该使用 chmod linux 命令。运行 php 的 linux 用户应具有对该路径的写入权限。

http://ss64.com/bash/chmod.html

https://www.linux.com/learn/understanding-linux-file-permissions

关于php - 无法在 ubuntu 服务器上打开 zip 文件错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39975242/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com