Jump to content

Zip problem


dfowler

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/108388-zip-problem/
Share on other sites

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);
}

Link to comment
https://forums.phpfreaks.com/topic/108388-zip-problem/#findComment-555655
Share on other sites

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.