tags:

views:

2254

answers:

5

i have a tutorial from a website Net Tuts which is used to upload a zip file and extract the data from within the file into the server.

copying and pasting the code straight from the web page did not work, an error occured half way through the script being processed.

Fatal error: Cannot instantiate non-existent class: ziparchive in /www/website_here.co.uk/httpdocs/test/functions.php on line 6

is it possible that this is to do with the version of PHP i am using. here is the code it gets stuck on

<?php

function openZip($file_to_open) {
 global $target;
 global $unique_folder;
 $zip = new ZipArchive();
  $x = $zip->open($file_to_open);
  if ($x === true) {
   $zip->extractTo($target . $unique_folder);
   $zip->close();

   unlink($file_to_open); #deletes the zip file. We no longer need it.
  } else {
   die("There was a problem. Please try again!");
  }
 }

?>

line 6: $zip = new ZipArchive();

i am using PHP version 4.3.9, Thanks for any help!

+2  A: 

On PHP 4 you absolutely need to install PECL zip 1.1.0 (or newer) in order to have access to the ZipArchive class. Follow these instructions.

If that is not possible, you will have to use the non-OO zip_open, zip_read etc. API.

vladr
Hi V, can i find out if zip support is installed using the php.ini file?
Ben McRae
@ben, are you running on windows or some flavor of unix?
vladr
im pretty sure its linux redhat enterprise edition! im not very good with ssh though, so im in abit of a problem haha.
Ben McRae
@ben, if you cannot ssh easily, just create a dummy page that prints the output of get_loaded_extensions and/or php_info on a page, and look for zip.
vladr
this is mentioned in the tutorial if it helps at all... To use the ZipArchive() class, you must first make sure that enable 'php_zip.dll' in your "php.ini" file. Simply search for that string, and then remove the semicolon. if that is any help at all!i dont have php_zip.dll mentioned in my php.ini
Ben McRae
@Ben, see my updated reply. The built-in zip module only offers basic zip_open, zip_close methods functionality. You really need PECL zip to use the ZipArchive class.
vladr
Thanks V for your help, unfortunatly im having problems following the php website. it mentions how to install is with windows,and then also with pear, which i have never used? how do you recommend i install it. i have downloaded the latest one from the site you linked me. thanks
Ben McRae
do you know of any non-oo methods? im not really a fan of oop anyway just because im quite new to programming. i have been doing really well, and this has been pretty much my trip in php :(
Ben McRae
A: 

You need a reference to the library containing the ZipArchive class

Chris Ballance
could this possibly be in zlib? i dont really have much experiance with oop styled coding as i am used to working with php 4! i have only been using php for a good couple of months :(
Ben McRae
+1  A: 

You could use PclZip too:

include('pclzip.lib.php');
$zip = new PclZip($file_to_open);
if ($zip->extract(PCLZIP_OPT_PATH, $target . $unique_folder) == 0) {
    die("There was a problem. Please try again!");
} else {
    unlink($file_to_open);
}

http://www.phpconcept.net/pclzip/index.en.php

cOle2
thanks for that, i have downloaded PclZip, but its over 5000 lines of code? will that have any load effect being so big?
Ben McRae
it will have an effect but it should be negligible (at least compared to the upload). On my localhost include()'ing that file adds about 0.01 seconds to the processing time.
cOle2
A: 
include('pclzip.lib.php');
$zip = new PclZip($file_to_open);
if ($zip->extract(PCLZIP_OPT_PATH, $target . $un_f) == 0) {
    close("close");
} else {
    unlink($file_op);
}

i agree use PclZip and if you don't have the time to code it up use [link text][1] u also need to utilize reference libraries

[1]: http://www.extractingdata.com/"extracting data"

brandon
A: 

start php

$zipn=$_REQUEST['zip'];
echo $zipn;

$zip = new ZipArchive;
echo $_SERVER['DOCUMENT_ROOT']."/";
if ($zip->open($zipn) === TRUE) {



$zip->extractTo($_SERVER['DOCUMENT_ROOT']."/");
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
close php

----------susheel [email protected]

susheel