Php Can';无法在ubuntu服务器上打开zip文件错误

Php Can';无法在ubuntu服务器上打开zip文件错误,php,csv,ubuntu,Php,Csv,Ubuntu,我必须一次下载多个csv文件。因此,我创建了zip文件,并将所有csv文件放入该zip文件中。一切正常,我可以下载我的zip文件并在本地主机上打开。我用的是windows操作系统 这是我的代码,来自export\u csv.php for($i=0; $i<$len; $i++) { $user_id = $array[$i]; #get user name $name = "..."; #get all day

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

这是我的代码,来自
export\u 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() {......}
我认为这个错误是许可问题。但我是ubuntu操作系统的新手,所以我不知道如何解决它

非常感谢您的帮助

更新


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

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

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


尝试授予您的文件777权限。应该小心…@WillParky93我已经添加了777权限
sudo chmod 777/opt/lampp/htdocs/project/export\u csv.php
。但仍然是同样的错误。非常感谢@gba的可能重复。将777权限添加到项目文件夹后,一切正常:)
[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