Jump to content

[SOLVED] ZIP File Open Errors


jonoc33

Recommended Posts

Hi guys,

I have made an update platform which auto generates a ZIP file from a folder's contents, using Rochak Chauhan's ZIP file creation tool along with an extended class to auto-find all of the files and folders automatically to add to the zip. The ZIP makes itself ok.

 

<?
session_start();
require_once("zipfile.php");
$createZip = new createDirZip;
$createZip->addDirectory('');
$createZip->get_files_from_folder('../development/', ''); // gets all files and folders from the development folder
$fileName = 'zip/zipfile-'.mysql_real_escape_string(htmlentities($_POST['version'])).'.zip';
$fd = fopen ($fileName, 'wb');
$out = fwrite ($fd, $createZip->getZippedfile());
fclose ($fd);
?>

 

Now, I have another application i've made which checks for updates, and uses the ZIP to unzip itself and overwrite everything to basically update the whole thing.

 

<?
include("inc/php/config.php");
// Functions to be used
function unzip($src_file, $dest_dir, $create_zip_name_dir=false, $overwrite=true)
{
      if (is_resource($zip = zip_open($src_file)))
      {         
          $splitter = ($create_zip_name_dir === true) ? "." : "/";
          if ($dest_dir === false) $dest_dir = substr($src_file, 0, strrpos($src_file, $splitter))."/";
          // Create the directories to the destination dir if they don't already exist
          create_dirs($dest_dir);
          // For every file in the zip-packet
          while ($zip_entry = zip_read($zip){
          {
            // Now we're going to create the directories in the destination directories
            // If the file is not in the root dir
            $pos_last_slash = strrpos(zip_entry_name($zip_entry), "/");
            if ($pos_last_slash !== false)
            {
              // Create the directory where the zip-entry should be saved (with a "/" at the end)
              create_dirs($dest_dir.substr(zip_entry_name($zip_entry), 0, $pos_last_slash+1));
            }
            // Open the entry
            if (zip_entry_open($zip,$zip_entry,"r"))
            {
              // The name of the file to save on the disk
              $file_name = $dest_dir.zip_entry_name($zip_entry);
              // Check if the files should be overwritten or not
              if ($overwrite === true || $overwrite === false && !is_file($file_name))
              {
                // Get the content of the zip entry
                $fstream = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));          
                if(!is_dir($file_name))           
                file_put_contents($file_name, $fstream );
              }
              // Close the entry
              zip_entry_close($zip_entry);
            }     
          }
          // Close the zip-file
          zip_close($zip);
      }
      else
      {
        echo "No Zip Archive Found.";
        return false;
      }
      return true;
  }
  else
  {
      if(version_compare(phpversion(), "5.2.0", "<"))
      $infoVersion="(use PHP 5.2.0 or later)";
      echo "You need to install/enable the php_zip.dll extension $infoVersion";
  }
}
function create_dirs($path)
{
  if (!is_dir($path))
  {
    $directory_path = "";
    $directories = explode("/",$path);
    array_pop($directories);
    foreach($directories as $directory)
    {
      $directory_path .= $directory."/";
      if (!is_dir($directory_path))
      {
        mkdir($directory_path);
      }
    }
  }
}
$current = $_POST['version'];
$con = mysql_connect("host", "user", "pass");
mysql_select_db("updateplatform_zipfile", $con);
$dbQueryV = mysql_query("SELECT * FROM updateplatform_zipfile WHERE version > '".$current."' ORDER BY id ASC");
while($dbRowV = mysql_fetch_array($dbQueryV)){
$version = $dbRowV['version'];
$file = file_get_contents("http://link.com/etc/zipfile/zipfile-".$version.".zip");
file_put_contents("zipfile-".$version.".zip", $file);
$zip = "zipfile-".$version.".zip";
unzip($zip, "", false, true);
unlink("zipfile-".$version.".zip");
}
?>

Now the strange thing is, that when I make a ZIP MANUALLY by downloading all the "development" files and zipping them up through winrar then uploading them to the correct location all manually, that above script which unzips it and overwrites it all works. When it's ZIPped up all done automatically through the Update Platform I made it comes up with these errors.

 

Warning: zip_entry_name() expects parameter 1 to be resource, integer given in /home/jonoc33/public_html/zipfile/process.update.php on line 93

 

Warning: zip_entry_open() expects parameter 2 to be resource, integer given in /home/jonoc33/public_html/zipfile/process.update.php on line 125

 

over and over again, hundreds of times, mostly due to it doing it for each file in the zip.

 

I need help!!

Link to comment
Share on other sites

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.