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
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
Share on other sites

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?

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.