Jump to content

Upload and Extract ZIP file


billy_111

Recommended Posts

Hey,

 

I'm trying to have a crack at some code i have bee following, don't know if this is in any way correct :-) but lets see what you guys think. So i need to upload and extract the contents of a ZIP file to a folder on the server called "reviewimages"..

 

This is my method:

 

    public function UploadZIPFileToServer(){

	move_uploaded_file($_FILES["zipfile"]["tmp_name"], "../reviewimages/" . $_FILES["zipfile"]["name"]);

	if(is_uploaded_file($_FILES['zipfile']['tmp_name'])){

		$zipfilename = basename($_FILES['zipfile']['name']);  
		$zip = zip_open($zipfilename);

		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);   
	}
}

 

And this is how i fire the method:

 

if(isset($_POST['uploadZIP'])){
    $message = Review::UploadZIPFileToServer();
    echo '<script type="text/javascript">window.location = "http://'.$_SERVER['SERVER_NAME'].$sitename.'manage-reviews.php"</script>';                
}

            <form enctype="multipart/form-data" action="" method="post" id="add-courses">
                <table>
                    <tr>
                        <td class="width"><label for="image">Upload ZIP file : </label></td>
                        <td><input type="hidden" name="MAX_FILE_SIZE" value="1000000000000" /><input type="file" name="zipfile" id="zipfile" value=""/></td>
                        <td><input type="submit" name="uploadZIP" value="Upload" /></td>
                    </tr>
                </table>
            </form> 

 

This uploads the ZIP file to the server into the "reviewimages" folder, but i need it to extract its contents which it does not do.. Any ideas?

 

Thanks

Billy

Link to comment
https://forums.phpfreaks.com/topic/204786-upload-and-extract-zip-file/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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