Does any one know of a good unzipping script?

My hosting company says they have:
path: /usr/bin/zip
path: /usr/bin/unzip
path: /usr/bin/gzip
path: /usr/bin/wget

the file I have is a .zip file

the hosting company has a unzip tool in there filemanager but I need to use this in my script as I am trying to do a number of things by a script each month it will get files and unzip them and update the database automatic so thats why I am looking for a script or example of unzipping a zip file

Thanks for the help I am thankful for all the help

Sincerely,
Christopher

    [man]zip[/man]

    If zip extension isn't working, then use one of [man]exec[/man]s to run /usr/bin/unzip.

      Well there are the general [man]zip[/man] functions included in any zip-enabled PHP installation.

      You can use [man]zip_open[/man] then [man]zip_read[/man] to read each item in the zip file, and [man]zip_entry_read[/man]

      I think with those, you can get on your way. I don't personally know of any zip scripts other than using PHP zip functions, or calling the zip or gzip binary through [man]exec[/man].

        This is a script I wrote I few weeks ago... have fun, it's in French 😛

        Upload your zip file in the same folder this script, chmod the directory to 777, same for the PHP file.

        Then change the value of $strZIP for the name of your ZIP file.

        It will create a directory and extract all files/directories...

        <?php
        
        $strZIP		= 'phpbbrc7to8.zip';
        $strZIP1	= preg_replace('/[\W]/', '_', $strZIP);
        $strZIP1	= preg_replace('/_+/', '_', $strZIP1);
        if(!file_exists('./' . $strZIP1)) {
        	mkdir($strZIP1, 0777) or die('impossible de créer le répertoire');
        }
        $objZIP	= new ZipArchive();
        $objZIP	= zip_open($strZIP);
        if($objZIP) {
        	while($objFichier	= zip_read($objZIP)) {
        		$strFichier	= zip_entry_name($objFichier);
        		echo '&#171; ' . $strFichier . ' &#187;<br />';
        		$arrRepertoires	= explode('/', $strFichier);
        		$strFichier1	= $arrRepertoires[count($arrRepertoires) - 1];
        		unset($arrRepertoires[count($arrRepertoires) - 1]);
        		$strRepertoire	= './' . $strZIP1 . '/';
        		for($intR = 0; $intR < count($arrRepertoires); $intR++) {
        			$strRepertoire	.= $arrRepertoires[$intR] . '/';
        			if(!file_exists($strRepertoire)) {
        				echo '* Création du répertoire &#171; ' . $strRepertoire . ' &#187;...';
        				echo ((@mkdir($strRepertoire)) ? ' ok !' : ' erreur !') . '<br />';
        				flush();
        			}
        		}
        		if($strFichier1 <> '') {
        			echo '* Ouverture...';
        			if(@zip_entry_open($objZIP, $objFichier)) {
        				echo ' ok !<br />';
        				echo '* Création du fichier...';
        				$resFichier	= @fopen(($strRepertoire . $strFichier1), 'wb+');
        				if(!$resFichier) {
        					echo ' erreur !<br />';
        				} else {
        					echo ' ok !<br />';
        					echo '* Copie du fichier...';
        					if(!@fwrite($resFichier, zip_entry_read($objFichier, zip_entry_filesize($objFichier)))) {
        						echo ' erreur !';
        					} else {
        						echo ' ok !';
        					}
        					echo '<br />';
        				}
        				fclose($resFichier);
        			} else {
        				echo ' erreur !<br />';
        			}
        		}
        		echo '<br />';
        		flush();
        	}
        } else {
        	echo 'échec';
        }
        
        ?>

          Is there a simple script to do this? I guess I will use the exec /user/bin/unzip way

          I tryed to do the exec way but did not have luck with it though.

          here is the code:

          <?PHP
          
          exec ("unzip /home80c/sub003/sc44514-NPGU/www/uploads/eoa01.zip");
          
          ?>
          

          Also have tried:

          
          <?php
          exec ("/usr/bin/unzip /home80c/sub003/sc44514-NPGU/www/uploads/eoa01.zip");
          ?>
          
          

            Well, does PHP have the rights to the .zip file? i.e. can PHP read and execute that file?

              You'll note only have to make sure that the .zip is readable, but you also need to make sure that the directory is writable as well.

              You might also try using [man]shell_exec/man instead and echo the output to see if there are any descriptive error messages.

                Write a Reply...