1

I am creating something like easy installer\setupper 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 a thing?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Rella
  • 65,003
  • 109
  • 363
  • 636

1 Answers1

2

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
  • 2,072
  • 2
  • 20
  • 24