PHP zip文件类错误?

PHP zip文件类错误?,php,class,Php,Class,我发现这门课很棒,除了。。。我指定输出目录,如下所示: $outputDir = "/backup/"; 但它不会在那里输出zip,而是在站点根目录上输出 这是指向该类的链接,您可以查看它:) 谢谢你的帮助 这是我调用该类的全部代码: include('scripts/zip.php'); $fileToZip = "License.txt"; $fileToZip1 = "CreateZipFileMac.inc.php"; $fileToZip2 = "CreateZipFile

我发现这门课很棒,除了。。。我指定输出目录,如下所示:

$outputDir = "/backup/";
但它不会在那里输出zip,而是在站点根目录上输出

这是指向该类的链接,您可以查看它:)

谢谢你的帮助


这是我调用该类的全部代码:

include('scripts/zip.php');

$fileToZip = "License.txt"; 
$fileToZip1 = "CreateZipFileMac.inc.php"; 
$fileToZip2 = "CreateZipFile.inc.php"; 

$directoryToZip = "./"; // This will zip all the file(s) in this present working directory 

$outputDir = '/backup/'; //Replace "/" with the name of the desired output directory. 
$zipName = "test.zip"; 

$createZipFile = new CreateZipFile; 

/* 
// Code to Zip a single file 
$createZipFile->addDirectory($outputDir); 
$fileContents=file_get_contents($fileToZip); 
$createZipFile->addFile($fileContents, $outputDir.$fileToZip); 
*/ 

//Code toZip a directory and all its files/subdirectories 
$createZipFile->zipDirectory($directoryToZip,$outputDir); 
$fd=fopen($zipName, "wb"); 
fwrite($fd,$createZipFile->getZippedfile()); 
fclose($fd);

我的猜测是,
$outDir
指的是文件系统路径,因此您正在查找文件系统根目录中的文件夹
/backup
(而不是域的根文件夹)

PHP很可能无法在这里编写,因此可能会默认为可以在哪里编写


您是否尝试过
/var/www/path/to/you/site/backup
以查看是否达到了预期效果?

没有可以将输出文件保存到目录的代码。 使用$outputDir,您只定义输出文件名的一部分

如果你想保存这个文件,你必须自己保存。 尝试在演示中添加如下内容:

$fs = fopen($outputDir."/".$zipName, "wb");
fwrite($fs, $createZipFile->getZippedfile()); 
fclose($fs);

嗯,好主意。我会尝试一下,然后告诉你结果:)我用这个代码替换了旧代码:$outputDir=$\u SERVER['DOCUMENT\u ROOT']./backup/;不走运。所以请按照我上面写的修改fopen。工作很有魅力。谢谢:)