2012-06-29 16 views
23
function uncompress($srcName, $dstName) { 
    $sfp = gzopen($srcName, "rb"); 
    $fp = fopen($dstName, "w"); 

    while ($string = gzread($sfp, 4096)) { 
     fwrite($fp, $string, strlen($string)); 
    } 
    gzclose($sfp); 
    fclose($fp); 
} 

मैं इस कोड की कोशिश की लेकिन यह काम नहीं करता कृपया मेरी मददमैं php का उपयोग कर gzip फ़ाइल को निकालने या असम्पीडित कैसे कर सकता हूं?

धन्यवाद

+7

हम की तुलना में "यह काम नहीं करता" एक बहुत अधिक की जरूरत है की कोशिश करो । यह क्या करता है? आपको क्या त्रुटि संदेश मिलते हैं? – meagar

+0

आपका कोड अच्छा दिखता है (यह 4kb ब्लॉक में डेटा को जोड़ता है) इसलिए यह रैम पर प्रकाश होना चाहिए। आपको क्या त्रुटि मिल रही है? – Lusitanian

+1

मुझे कुछ भी नहीं मिला है, मैं अपनी किसी भी फाइल को असम्पीड्रेस नहीं करता – Farzamtm

उत्तर

50

इस पाया here

//This input should be from somewhere else, hard-coded in this example 
$file_name = '2013-07-16.dump.gz'; 

// Raising this value may increase performance 
$buffer_size = 4096; // read 4kb at a time 
$out_file_name = str_replace('.gz', '', $file_name); 

// Open our files (in binary mode) 
$file = gzopen($file_name, 'rb'); 
$out_file = fopen($out_file_name, 'wb'); 

// Keep repeating until the end of the input file 
while (!gzeof($file)) { 
    // Read buffer-size bytes 
    // Both fwrite and gzread and binary-safe 
    fwrite($out_file, gzread($file, $buffer_size)); 
} 

// Files are done, close files 
fclose($out_file); 
gzclose($file); 
संबंधित मुद्दे

 संबंधित मुद्दे