Jon N Posted July 10, 2008 Share Posted July 10, 2008 Greetings, I'm prepared to feel like an idiot for asking such a noobish question, but here goes. The www user on my server is unable to exec("zip...") on our Unix server, so I've been faced with utilizing PHP to zip files (it needs to be Zip/PKzip compatible, NOT gzip or bzip2). Server Details PHP 4.4.2 Registered PHP Streams: php, http, ftp, https, ftps, compress.zlib, compress.bzip2 zip Zip support enabled zlib ZLib Support enabled Compiled Version 1.2.2 Linked Version 1.2.2 Now, when I try to run the following code: $zip = new ZipArchive; $res = $zip->open('test.zip', ZipArchive::CREATE); if ($res === TRUE) { $zip->addFile('data.kml'); $zip->close(); echo 'ok'; } else { echo 'failed'; } I get an error (the second line above is 232): Parse error: syntax error, unexpected ')', expecting '(' in _______ on line 232 Alas, I have tried over and over again to get some sort of zip going on, but to no avail. Is the PHP version being too old causing the syntax error? Do I not have ZIP support like above in this version? Is there a way to write a zip file in 4.4.2? Please help! Link to comment https://forums.phpfreaks.com/topic/114150-php-compression-nightmare/ Share on other sites More sharing options...
DarkWater Posted July 10, 2008 Share Posted July 10, 2008 Which line is that? Link to comment https://forums.phpfreaks.com/topic/114150-php-compression-nightmare/#findComment-586761 Share on other sites More sharing options...
Jon N Posted July 10, 2008 Author Share Posted July 10, 2008 The second line of code Link to comment https://forums.phpfreaks.com/topic/114150-php-compression-nightmare/#findComment-586763 Share on other sites More sharing options...
discomatt Posted July 10, 2008 Share Posted July 10, 2008 Show us about 50 lines above it... it could be well above the actual error. Link to comment https://forums.phpfreaks.com/topic/114150-php-compression-nightmare/#findComment-586772 Share on other sites More sharing options...
Jon N Posted July 10, 2008 Author Share Posted July 10, 2008 It's actually in a file with a bunch of if statements, and I've only called this one specific if statement, alas nothing before or after it is called. if($test=="y") { $zip = new ZipArchive; $res = $zip->open('test.zip', ZipArchive::CREATE); if ($res === TRUE) { $zip->addFile('data.kml'); $zip->close(); echo 'ok'; } else { echo 'failed'; } } Link to comment https://forums.phpfreaks.com/topic/114150-php-compression-nightmare/#findComment-586780 Share on other sites More sharing options...
DarkWater Posted July 10, 2008 Share Posted July 10, 2008 1) That doesn't give me any errors. Well, the line that you said gave you an error. 2) Why are you using such an old version of PHP? Link to comment https://forums.phpfreaks.com/topic/114150-php-compression-nightmare/#findComment-586786 Share on other sites More sharing options...
Jon N Posted July 10, 2008 Author Share Posted July 10, 2008 Damn, it must be a problem with the version I have then, right? I can't update php as it's not my server. It's a development server with a lot of important code. Revising such may take ages if we update. I guess I'm most curious as to whether or not there is a workaround for compressing files in 4.4.2? Link to comment https://forums.phpfreaks.com/topic/114150-php-compression-nightmare/#findComment-586791 Share on other sites More sharing options...
Jon N Posted July 10, 2008 Author Share Posted July 10, 2008 Should I use a class like this instead? $ARCHIVE = new zip; $ARCHIVE->makeZip('./','./toto.zip'); // make an ZIP archive var_export($ARCHIVE->infosZip('./toto.zip'), false); // get infos of this ZIP archive (without files content) var_export($ARCHIVE->infosZip('./toto.zip')); // get infos of this ZIP archive (with files content) $ARCHIVE->extractZip('./toto.zip', './1/'); // class zip { public function infosZip ($src, $data=true) { if (($zip = zip_open(realpath($src)))) { while (($zip_entry = zip_read($zip))) { $path = zip_entry_name($zip_entry); if (zip_entry_open($zip, $zip_entry, "r")) { $content[$path] = array ( 'Ratio' => zip_entry_filesize($zip_entry) ? round(100-zip_entry_compressedsize($zip_entry) / zip_entry_filesize($zip_entry)*100, 1) : false, 'Size' => zip_entry_compressedsize($zip_entry), 'NormalSize' => zip_entry_filesize($zip_entry)); if ($data) $content[$path]['Data'] = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); zip_entry_close($zip_entry); } else $content[$path] = false; } zip_close($zip); return $content; } return false; } public function extractZip ($src, $dest) { $zip = new ZipArchive; if ($zip->open($src)===true) { $zip->extractTo($dest); $zip->close(); return true; } return false; } public function makeZip ($src, $dest) { $zip = new ZipArchive; $src = is_array($src) ? $src : array($src); if ($zip->open($dest, ZipArchive::CREATE) === true) { foreach ($src as $item) if (file_exists($item)) $this->addZipItem($zip, realpath(dirname($item)).'/', realpath($item).'/'); $zip->close(); return true; } return false; } private function addZipItem ($zip, $racine, $dir) { if (is_dir($dir)) { $zip->addEmptyDir(str_replace($racine, '', $dir)); $lst = scandir($dir); array_shift($lst); array_shift($lst); foreach ($lst as $item) $this->addZipItem($zip, $racine, $dir.$item.(is_dir($dir.$item)?'/':'')); } elseif (is_file($dir)) $zip->addFile($dir, str_replace($racine, '', $dir)); } } Link to comment https://forums.phpfreaks.com/topic/114150-php-compression-nightmare/#findComment-586862 Share on other sites More sharing options...
Jon N Posted July 10, 2008 Author Share Posted July 10, 2008 Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in _________.php on line 241 Line 241 from above is: public function infosZip ($src, $data=true) Link to comment https://forums.phpfreaks.com/topic/114150-php-compression-nightmare/#findComment-586912 Share on other sites More sharing options...
DarkWater Posted July 10, 2008 Share Posted July 10, 2008 I don't think PHP4 has visibility modifiers. I'd seriously suggest upgrading. Link to comment https://forums.phpfreaks.com/topic/114150-php-compression-nightmare/#findComment-586918 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.