Hi,
I am trying to upload a Zip file and extract it using the following code:
class Zip {
public function extract($filename, $targetDir){
$zip = zip_open($filename);
if ($zip) {
while ($zip_entry = zip_read($zip)) {
$fp = fopen($targetDir . zip_entry_name($zip_entry), "w");
if (zip_entry_open($zip, $zip_entry, "r")) {
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
fwrite($fp,"$buf");
zip_entry_close($zip_entry);
fclose($fp);
}
}
zip_close($zip);
}
}
}
I call the method like so:
if(isset($_POST['add']) && $_POST['add'] == 'Upload'):
$root = "../view/documents/";
$target_path = $root.basename( $_FILES['ZipFile']['name']);
if(isset($_FILES['ZipFile']['name']) && $_FILES['ZipFile']['name'] != ''):
Zip::extract($_FILES['ZipFile']['name'] ,$target_path);
endif;
endif;
And finally my input element is like so:
<input type="file" name="ZipFile" id="ZipFile" value=""/>
But i get the following error when i try to upload:
Warning: zip_read() expects parameter 1 to be resource, integer given in public_html/library/Zip.class.php on line 11
Warning: zip_close() expects parameter 1 to be resource, integer given in public_html/library/Zip.class.php on line 22
Any ideas what i am doing wrong, i just want to be able to extract the Zip file int a folder called “documents”…
Am i missing something?