Jump to content

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

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.