Symfony Zip存档文件0 ko

时间:2018-03-21 14:31:48

标签: php zip symfony1

更新决议:

$config_server = sfYaml::load(sfConfig::get('sf_root_dir').'/config/server.yml');
        $url_root = $config_server[sfConfig::get('sf_environment')]['url_root'];
        $path_root = $config_server[sfConfig::get('sf_environment')]['path_root'];
        $path_upload = $config_server[sfConfig::get('sf_environment')]['path_upload'];

        $zipname = 'file.zip';
        $zip = new ZipArchive();
        $tmp_file = tempnam('.','');
        $zip->open($tmp_file, ZipArchive::CREATE);

        //on récupère la collection de pièces jointes
        $files = Doctrine::getTable('PieceJointe')->getPiecesJointes($id_pjs);

        foreach($files as $file){

            //on récupère le fichier
            $realfile =  $path_upload . $file->getPathPj() . $file->getNomPj();

            //on récupère le nom du fichier
            $filename = $file->getNomPj();

            $download_file = file_get_contents($realfile);
            $zip->addFromString($filename, $download_file);

        }

        $zip->close();

        header('Content-disposition: attachment; filename='.$zipname);
        header('Content-type: application/zip');
        readfile($tmp_file);

        return sfView::NONE;

当我运行此脚本时,我下载了包含文件的存档,但文件为空。

当我var_dump变量$ Downloadfile时,我得到文件的完整路径:

  

的字符串(140)   “C:/瓦帕/网络/ sigap /上传/ MI / appel_projet / CLOS / candidature_TEST_laureat_TEST2TEST8888888_suivi_projet / SIGAP_SFD_Evol_50341-Suivi_v00(3)的.docx”

似乎我没有得到文件的文件内容。

这是我提取arhive时计算机中的结果:

enter image description here

我做错了什么?我只想将我的文件存入档案。非常感谢您的帮助。

  $files = array();
                foreach($this->rapports as $ra){

                $files[] = $ra->getPieceJointe();

            }


            $config_server = sfYaml::load(sfConfig::get('sf_root_dir').'/config/server.yml');
            $url_root = $config_server[sfConfig::get('sf_environment')]['url_root'];
            $path_root = $config_server[sfConfig::get('sf_environment')]['path_root'];
            $path_upload = $config_server[sfConfig::get('sf_environment')]['path_upload'];


            $zip = new ZipArchive;
    $zipName = 'depots.zip';
    $zip->open($zipName,  ZipArchive::CREATE);
    foreach ($files as $file) {

        $Downloadfile = $path_upload . $file['path_pj'] . $file['nom_pj'];

        //var_dump($Downloadfile); 

        //die;

        $zip->addFromString(basename($file['path_pj']) , file_get_contents($Downloadfile)); 

    }
    $zip->close();

    header('Content-Type', 'application/zip');
    header('Content-disposition: attachment; filename="' . $zipName . '"');
    header('Content-Length: ' . filesize($zipName));
    readfile($zipName);

    return sfView::NONE;

0 个答案:

没有答案