dfowler Posted June 2, 2008 Share Posted June 2, 2008 Hey guys, I have some code I've been working with for quite awhile now. Here is some test code I've created and it isn't working at all. <?php error_reporting(E_ALL); $ftp_server = $ipaddress; $ftp_user_name = $user; $ftp_user_pass = $pass; $image = array(); $pieces = array(); // 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); // get contents of the current directory $contents = ftp_nlist($conn_id, "/htdocs/"); foreach($contents as $c) { if (eregi('property', $c)) { $pieces = explode("/", $c); } } foreach ($pieces as $p){ if (eregi('property', $p)) { $zip_name = $p; } } $test = zip_open($zip_name); if ($test){ $zip_close(); echo 'ok'; } else { echo 'failed'; } ?> the $zip_name ends up being filled with 'property13234.zip' (I've echo'd $zip_name and it confirms this), however the page shows up blank. What am I doing wrong here? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted June 2, 2008 Share Posted June 2, 2008 I would imagine the problem relates to that fact that zip_open doesn't return false or error, it returns an error number. So, you should be doing: $test = zip_open($zip_name); if (is_resource($test)){ $zip_close(); echo 'ok'; } else { echo 'failed'; } And courtesy of saulius at solmetra dot lt from http://www.php.net/zip_open (strangely there appears to be no official documentation on the error numbers, unless im being blind) : function zipFileErrMsg($errno) { // using constant name as a string to make this function PHP4 compatible $zipFileFunctionsErrors = array( 'ZIPARCHIVE::ER_MULTIDISK' => 'Multi-disk zip archives not supported.', 'ZIPARCHIVE::ER_RENAME' => 'Renaming temporary file failed.', 'ZIPARCHIVE::ER_CLOSE' => 'Closing zip archive failed', 'ZIPARCHIVE::ER_SEEK' => 'Seek error', 'ZIPARCHIVE::ER_READ' => 'Read error', 'ZIPARCHIVE::ER_WRITE' => 'Write error', 'ZIPARCHIVE::ER_CRC' => 'CRC error', 'ZIPARCHIVE::ER_ZIPCLOSED' => 'Containing zip archive was closed', 'ZIPARCHIVE::ER_NOENT' => 'No such file.', 'ZIPARCHIVE::ER_EXISTS' => 'File already exists', 'ZIPARCHIVE::ER_OPEN' => 'Can\'t open file', 'ZIPARCHIVE::ER_TMPOPEN' => 'Failure to create temporary file.', 'ZIPARCHIVE::ER_ZLIB' => 'Zlib error', 'ZIPARCHIVE::ER_MEMORY' => 'Memory allocation failure', 'ZIPARCHIVE::ER_CHANGED' => 'Entry has been changed', 'ZIPARCHIVE::ER_COMPNOTSUPP' => 'Compression method not supported.', 'ZIPARCHIVE::ER_EOF' => 'Premature EOF', 'ZIPARCHIVE::ER_INVAL' => 'Invalid argument', 'ZIPARCHIVE::ER_NOZIP' => 'Not a zip archive', 'ZIPARCHIVE::ER_INTERNAL' => 'Internal error', 'ZIPARCHIVE::ER_INCONS' => 'Zip archive inconsistent', 'ZIPARCHIVE::ER_REMOVE' => 'Can\'t remove file', 'ZIPARCHIVE::ER_DELETED' => 'Entry has been deleted', ); $errmsg = 'unknown'; foreach ($zipFileFunctionsErrors as $constName => $errorMessage) { if (defined($constName) and constant($constName) === $errno) { return 'Zip File Function error: '.$errorMessage; } } return 'Zip File Function error: unknown'; } //making your code: $test = zip_open($zip_name); if (is_resource($test)){ $zip_close(); echo 'ok'; } else { echo 'failed<br />'; echo zipFileErrMsg($zip); } Quote Link to comment Share on other sites More sharing options...
dfowler Posted June 2, 2008 Author Share Posted June 2, 2008 I tried implementing what you showed (the error messages is great), however I am still only getting a blank page on return. Is there a setting that needs to be turned on the the server to allow these functions to work? Any other reason why this could be happening? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted June 2, 2008 Share Posted June 2, 2008 Perhaps you have the display_errors off? Add this: ini_set('display_errors','On'); To the top of your script. Quote Link to comment Share on other sites More sharing options...
dfowler Posted June 2, 2008 Author Share Posted June 2, 2008 Ok, now I'm more confused. The server is running PHP Version 5.2.5. However, I keep getting the following error: Fatal error: Call to undefined function zip_open() in /.../.../htdocs/test.php on line 70 Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted June 2, 2008 Share Posted June 2, 2008 Ok, well there lies your problem. The library isn't enabled by default. http://uk.php.net/manual/en/zip.installation.php Quote Link to comment Share on other sites More sharing options...
dfowler Posted June 10, 2008 Author Share Posted June 10, 2008 Does anybody know of a way to work with zips on a server running PHP 5.1? The server isn't going to upgrade so I have to run this on a server with 5.1, and I can't find a way why. Quote Link to comment Share on other sites More sharing options...
discomatt Posted June 10, 2008 Share Posted June 10, 2008 There are ways http://www.google.ca/search?q=php+zip+class Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.