0

私はdrupalモジュールを作成しました。モジュールの機能の1つは、いくつかのファイルを圧縮してzipパッケージにすることです。ローカル環境(xampp)では正常に動作しますが、サーバーでは失敗します。私のサーバーではphpzip拡張機能が有効になっています。これは、php情報でzip情報を確認でき、phpでファイルを解凍できるためです。

その上、私はすでに0777になるようにファイルをchmodします。

私のコード:

$folder = file_directory_path();

$zip = new ZipArchive();

if ($zip->open('b.zip', ZIPARCHIVE::CREATE) === TRUE) {

    foreach ( $files as $file ) {
        drupal_set_message(t($file)); // I can see the the message on this stpe
        $zip->addFile($file);
    }

    $zip->close();
    if (file_exists('b.zip')) {

        copy('b.zip', $folder . '/b.zip');
        unlink('b.zip');
        global $base_url;
        variable_set('zippath', $base_url . $folder . '/b.zip');
        drupal_set_message(t('new zip package has been created'));
    }
} else {
    drupal_set_message(t('new zip package failed'));
}
4

2 に答える 2

1

はい..私はあなたが何を意味するのか知っています..これは3つの可能性です

  • 書き込み権限があります
  • フルパスを使用しませんでした
  • フォルダをファイルとして含めています

あなたはこれを試すことができます

error_reporting(E_ALL);
ini_set("display_errors", "On");


$fullPath = __DIR__ ; // <-------- Full Path to directory
$fileZip = __DIR__ . "/b.zip";  // <---  Full path to zip

if(!is_writable($fullPath))
{
    trigger_error("You can't Write here");
}

$files = scandir($fullPath); // <--- Just to emulate your files
touch($fileZip); // <----------------- Try Creating the file temopary 


$zip = new ZipArchive();
if ($zip->open($fileZip, ZIPARCHIVE::CREATE) === TRUE) {

    foreach ( $files as $file ) {
        if ($file == "." || $file == "..")
            continue;
        $fileFull = $fullPath . "/$file";
        if (is_file($fileFull)) { // <-------------- Make Sure its a file
            $zip->addFile($fileFull, $file);
        }

        // Play your ball
    }
    $zip->close();
} else {
    echo "Failed";
}
于 2012-10-18T02:57:40.547 に答える
0

rarまたはzipコマンドを使用してzipを作成することをお勧めします。私はLinuxを使用しており、PHPシステムで次のように実行しています。

$folder = 'your_folder';  // folder contains files to be archived
$zipFileName  = 'Your_file_name'; // zip file name
$command = 'rar a -r ' . $zipFileName . ' ' . $folder . '/';
exec($command);

その非常に速い。ただし、システムにrarパッケージをインストールする必要があります。

ありがとう

于 2012-10-18T05:55:48.830 に答える