Blog > php

PHP Unzip and Upload files


Warning: fopen(/home/niels/domains/nielsmusschoot.com/public_html/wp-content/plugins/fv-code-highlighter/cache/ddab332977e55b5f6fb7461404e3cae4cefb8f24) [function.fopen]: failed to open stream: Permission denied in /home/niels/domains/nielsmusschoot.com/public_html/wp-content/plugins/fv-code-highlighter/Includes/Cache.php on line 69

This is a very usefull piece of code if you would like to unzip and upload files onto your server.  Make sure the directory you want to extract it to has write permissions.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
     $zip = new ZipArchive;
     $res = $zip-&gt;open('my_zip_file.zip');
     if ( $res )
     {
         $zip-&gt;extractTo('my_extract_to_dir/');
         $zip-&gt;close();
         echo 'ok';
     }
     else
     {
         echo 'failed';
     }
?>

By Niels Musschoot
November 24, 2010, 2:01pm
Categories
Web Development