0

私はこの素晴らしいクラスを見つけました、それを除いてすべてうまくいきます...私は次のように出力ディレクトリを特定します:

$outputDir = "/backup/";

ただし、zipは出力されず、サイトルートに出力されます。

これはクラスへのリンクなので、チェックアウトできます:)

http://www.phpclasses.org/browse/file/9525.html

助けてくれてありがとう!


これは、私がクラスを呼び出すコード全体です。

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);
4

2 に答える 2

1

私の推測では$outDir、これはファイルシステムパスを参照しているため、ファイルシステムのルートにあるフォルダーを探してい/backupます(ドメインのルートフォルダーからの相対パスではありません)。

PHPはここに書き込めない可能性が高いため、デフォルトで可能な場所に書き込める可能性があります。

/var/www/path/to/you/site/backupそれが望ましい効果をもたらすかどうかを確認しようとしましたか?

于 2012-06-14T11:19:37.380 に答える
1

出力ファイルをディレクトリに保存できるコードはありません。$ outputDirを使用すると、出力ファイル名の一部のみを定義できます。

このファイルを保存したい場合は、自分で保存する必要があります。デモに次のようなものを追加してみてください。

$fs = fopen($outputDir."/".$zipName, "wb");
fwrite($fs, $createZipFile->getZippedfile()); 
fclose($fs);
于 2012-06-14T11:51:36.350 に答える