lildog Posted June 30, 2008 Share Posted June 30, 2008 A recent tax law has forced me to be able to unzip a large file on my server. it is only 6.5megs zipped but expands to a 45meg text file. The problem is my memory limit is only 20M so I get an error. Any ideas? Can I unzip bits of the file and write it to a file, maybe stream it somehow? Segment it and then decompress the segments? I have hit a roadblock and don't know where to look anymore. Anything would be a great help. todd Link to comment Share on other sites More sharing options...
Jan Zonjee Posted June 30, 2008 Share Posted June 30, 2008 A recent tax law has forced me to be able to unzip a large file on my server. it is only 6.5megs zipped but expands to a 45meg text file. The problem is my memory limit is only 20M so I get an error. Any ideas? Can I unzip bits of the file and write it to a file, maybe stream it somehow? Segment it and then decompress the segments? I have hit a roadblock and don't know where to look anymore. Perhaps the Easy Archives class, see also the PHP site? Link to comment Share on other sites More sharing options...
lildog Posted June 30, 2008 Author Share Posted June 30, 2008 Thanks Jan....I can already decompress and work with smaller archives. The problem arises when the decompressed file is larger than my servers memory_limit. Unfortunately it is a shared server and I cannot just raise it. I am hoping someone can shed some light on zip segments... when they are decompressed can they be decompressed individually in succession or are they joined back into a large file before being uncompressed? lildog Link to comment Share on other sites More sharing options...
Jan Zonjee Posted June 30, 2008 Share Posted June 30, 2008 The problem arises when the decompressed file is larger than my servers memory_limit. Unfortunately it is a shared server and I cannot just raise it. I am hoping someone can shed some light on zip segments... when they are decompressed can they be decompressed individually in succession or are they joined back into a large file before being uncompressed? Well, if that class can use zip_read in a similar manner as gzgets does in the function below for a gzip'ed file than it would mean it reads in a small part, decompresses it and writes it to the uncompressed file: function osc_gunzip($directory, $file_in, $delete_file = false) { $in_file = $directory . $file_in; $out_file = substr($in_file, 0, -3); if (!file_exists ($in_file) || !is_readable ($in_file)) { return false; } if (file_exists($out_file)) { return false; } $fin_file = gzopen($in_file, "rb"); if (!$fout_file = fopen($out_file, "wb")) { return false; } while (!gzeof ($fin_file)) { $buffer = gzgets($fin_file, 8192); fputs($fout_file, $buffer, 8192); } gzclose($fin_file); fclose($fout_file); if ($delete_file == true) { unlink($in_file); } return true; } Link to comment Share on other sites More sharing options...
lildog Posted July 1, 2008 Author Share Posted July 1, 2008 Thank you, I will try this out. todd Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.