2017-05-24 4 views
0

私はPHPスクリプトでBZ2ファイルを解凍しようとするが、私はこのエラーを持っている:私は達成しようとしている何解凍BZ2(__halt_compiler();が見つからない)

PHP Fatal error: Uncaught UnexpectedValueException: internal corruption of phar "/Users/apple/projects/asystem/database/dump/xxxx.sql.bz2" (__HALT_COMPILER(); not found) in /Users/apple/projects/asystem/database/dump/dump_auctions.php:33 Stack trace: 0 /Users/apple/projects/asystem/database/dump/dump_auctions.php(33): PharData->__construct('auct_auctions_x...') 1 {main} thrown in /Users/apple/projects/asystem/database/dump/dump_auctions.php on line 33

がある:からファイルをダウンロードしてくださいFTP、解凍してデータベースにインポートします。しかし、イムBZ2を解凍するに引っかかって

これは私のコードです:

<?php 

    // Download Auctions dump 

    // define some variables 
    $local_file = "xxxx.sql.bz2"; 
    $server_file = "xxxx.sql.bz2"; 

    //-- Connection Settings 
    $ftp_server = "xxxxx.xxxxx.com"; // Address of FTP server. 
    $ftp_user_name = "xxxxxx_user"; // Username 
    $ftp_user_pass = "xxxxx"; // Password 


    // set up basic connection 
    $conn_id = ftp_connect($ftp_server); 

    // login with username and password 
    $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 

    // try to download $server_file and save to $local_file 
    if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) { 
     echo "Successfully written to $local_file\n"; 
    } else { 
     echo "There was a problem\n"; 
    } 

    // close the connection 
    ftp_close($conn_id); 

    // unzip file 
    $p = new PharData('xxxx.sql.bz2'); 
    $p->decompress(); 
?> 

答えて

0

私は解決策hereを見つけました。

// set input and output files 
$out = 'xxxx.sql'; 
$in = 'xxxx.sql.bz2'; 

// decompress file using BZIP2 
if (file_exists($in)) { 
    $data = ''; 
    $bz = bzopen($in, 'r') or die('ERROR: Cannot open input file!'); 
    while (!feof($bz)) { 
     $data .= bzread($bz, 4096) or die('ERROR: Cannot read from input file');; 
    } 
    bzclose($bz); 
    file_put_contents($out, $data) or die('ERROR: Cannot write to output file!'); 
    echo 'Decompression complete.'; 
} 
:ちょうどこのコードを使用し

関連する問題