affordit Posted February 17, 2011 Share Posted February 17, 2011 Hello all I have been trying to loop thru a dir. of .gz files and unzip them into the dir. that this script runs in, can not seem to get it can someone help? Here is what I have $buffer_size = 4096; // read 4kb at a time if ($handle = opendir('./gz')) { while ($in_file = readdir($handle)) { if($in_file != "." && $in_file != ".." && $in_file != "index.php"){ $file = gzopen($in_name, 'rb'); $out_file = fopen($out_file_name, 'wb'); while(!gzeof($file)) { fwrite($out_file, gzread($file, $buffer_size)); } fclose($out_file); gzclose($file); } } closedir($handle); } Thank all Link to comment https://forums.phpfreaks.com/topic/228036-help-with-unzipping-gz-files/ Share on other sites More sharing options...
affordit Posted February 17, 2011 Author Share Posted February 17, 2011 I changed to this and still get nothing $buffer_size = 4096; // read 4kb at a time if ($handle = opendir('./gz')) { while ($in_file = readdir($handle)) { if($in_file != "." && $in_file != ".." && $in_file != "index.php"){ $out_file_name = str_replace('.gz', '', $in_file); $file = gzopen($out_file_name, 'rb'); $out_file = fopen($out_file_name, 'wb'); while(!gzeof($file)) { fwrite($out_file, gzread($file, $buffer_size)); fclose($out_file); gzclose($file); } } } closedir($handle); } Link to comment https://forums.phpfreaks.com/topic/228036-help-with-unzipping-gz-files/#findComment-1175874 Share on other sites More sharing options...
affordit Posted February 17, 2011 Author Share Posted February 17, 2011 I got it to creat the .txt file but not write anything to it??? Link to comment https://forums.phpfreaks.com/topic/228036-help-with-unzipping-gz-files/#findComment-1175889 Share on other sites More sharing options...
affordit Posted February 18, 2011 Author Share Posted February 18, 2011 No one has any ideas? Link to comment https://forums.phpfreaks.com/topic/228036-help-with-unzipping-gz-files/#findComment-1175961 Share on other sites More sharing options...
kenrbnsn Posted February 18, 2011 Share Posted February 18, 2011 You might want to try using gzfile to read the file into an array and then using file_put_contents to create the new file: <?php $files = glob('./gz/*.gz'); foreach ($files as $in_file) { $tmp = gzfile($in_file); file_put_contents(str_replace('.gz','',basename($in_file)),implode('',$tmp)); } ?> Note: completely untested. Ken Link to comment https://forums.phpfreaks.com/topic/228036-help-with-unzipping-gz-files/#findComment-1175978 Share on other sites More sharing options...
affordit Posted February 18, 2011 Author Share Posted February 18, 2011 Nope did not work got nothing no errors no files created. Thanks for trying Ken After about 2 days of this I'm shot. Thank you. Link to comment https://forums.phpfreaks.com/topic/228036-help-with-unzipping-gz-files/#findComment-1176031 Share on other sites More sharing options...
kenrbnsn Posted February 18, 2011 Share Posted February 18, 2011 I just tried my code on my server and it worked fine. There was one .gz file in my gz directory and when the program completed the expanded file was in the directory where I ran the code. You might want to put a debugging line in your code, something like: <?php $files = glob('./gz/*.gz'); foreach ($files as $in_file) { $tmp = gzfile($in_file); echo basename($in_file) . ' ==> ' . str_replace('.gz','',basename($in_file)) . "\n"; file_put_contents(str_replace('.gz','',basename($in_file)),implode('',$tmp)); } ?> to see if you're even getting the files. Ken ?> Link to comment https://forums.phpfreaks.com/topic/228036-help-with-unzipping-gz-files/#findComment-1176041 Share on other sites More sharing options...
affordit Posted February 18, 2011 Author Share Posted February 18, 2011 This is what came up Body_Candy-Product_Catalog.txt.gz ==> Body_Candy-Product_Catalog.txt But no file created Link to comment https://forums.phpfreaks.com/topic/228036-help-with-unzipping-gz-files/#findComment-1176048 Share on other sites More sharing options...
affordit Posted February 18, 2011 Author Share Posted February 18, 2011 Getting a memory error any way to get around it? PHP Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 16777326 bytes) on line 7 Link to comment https://forums.phpfreaks.com/topic/228036-help-with-unzipping-gz-files/#findComment-1176062 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.