你好,我正在尝试用Symfony 创建一个Zip文件
从ZIPArchive的php文档中,我正在执行以下操作:
/**
* @Route(
* "/up/waka/download/",
* name="getEbook"
* )
* @Method("GET")
*/
public function getEbookAction()
{
$zip = new 'ZipArchive();
$filename = "./fdgfdgdfgdf2.zip";
if ($zip->open($filename, ZipArchive::CREATE)!==TRUE) {
exit("cannot open <$filename>'n");
}
$zip->addFromString("testfilephp.txt" . time(), "#1 This is a test string added as testfilephp.txt.'n");
$zip->addFromString("testfilephp2.txt" . time(), "#2 This is a test string added as testfilephp2.txt.'n");
$zip->close();
dump($this->container, $zip);
return $this->render('AppBundle:Front:index.html.twig')
->setSharedMaxAge(600);
}
我返回一个视图是因为控制器需要返回一些东西,我选择了一个视图,它是用于演示的。dump($this->container, $zip);
返回以下内容:
ZipArchive {#1764 ▼
+"status": 12
+"statusSys": 13
+"numFiles": 2
+"filename": "/var/www/html/proyectname/web/fdgfdgdfgdf2.zip"
+"comment": ""
}
但是,我在这条路线上看不到zip文件。我的错误是什么?
哪些权限拥有"web"目录?尝试将其设置为755
- 检查phpinfo();如果启用了Zip
- 检查php.ini中是否存在"extension=zip.so"
如果这两个选项都是错误的,请尝试安装zip包:
$ pecl install zip
并手动将extension=zip.so添加到php.ini中。重新启动PHP。