views:

220

answers:

1

I am creating something like eazy installer\setuper for my CMS. When user downloads .zip with my CMS and unpacks it into some folder on his php server he sees a file - install.php and a zip folder named - Contents.zip I need some php function to extract files from that Contents.zip zip file and than delete that file. (if it is possible I want to give different rights to files\folders extracted from there right after folder unZipping)

How to do such thing?

+2  A: 

you could use PHP ZipArchive library to for you purpose.

also, an code example from the documentation you might find useful.

<?php

$zip = new ZipArchive();
$filename = "./test112.zip";

if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
    exit("cannot open <$filename>\n");
}

$zip->addFromString("testfilephp.txt" . time(), "#1 This is a test string added as testfilephp.txt.\n");
$zip->addFromString("testfilephp2.txt" . time(), "#2 This is a test string added as testfilephp2.txt.\n");
$zip->addFile($thisdir . "/too.php","/testfromfile.php");
echo "numfiles: " . $zip->numFiles . "\n";
echo "status:" . $zip->status . "\n";
$zip->close();
?>

for changing the file permissions you can use PHP builtin function chmod.

for example

chmod("/somedir/somefile", 0600);

to delete the file you can use, php builtin unlink

for example,

unlink('test.html');
unlink('testdir');

I would strongly recommend yuo to go through the official PHP documentation.

phoenix24
is that "PHP ZipArchive library" part of official php 5.2 defalt apache php?
Blender
and where do you delete that zip file?
Blender
@Ole yeah, ZipArchive comes with the official distribution; however it has an external dependency on http://www.zlib.net/
phoenix24
so it is possible when somebody buys Apache Web Hosting from some provider he will not be able to use this function?
Blender