退房其他的例子,但是這是我得到它的工作:
<?php
$dirArray = array();
/* creates a compressed zip file */
$zip = new ZipArchive;
if ($zip->open('dataminefiles.zip', ZIPARCHIVE::CREATE) !== TRUE) {
die ("Could not open archive");
}
// open the current dir
if ($handle = opendir('.')) {
while (false !== ($entry = readdir($handle))) {
// ignore hidden files
if ($entry != "." && $entry != "..") {
// only zip specific files
if (substr($entry,-3,3) == "jpg" || substr($entry,-3,3) == "pdf" || substr($entry,-3,3) == "lsx" || substr($entry,-3,3) == "xls" || substr($entry,-3,3) == "doc" || substr($entry,-3,3) == "txt" || substr($entry,-3,3) == "png" || substr($entry,-3,3) == "gif" || substr($entry,-3,3) == "peg") {
// if allowed, add them to the array
$dirArray[] = $entry;
}
}
}
closedir($handle);
}
$indexCount = count($dirArray);
sort($dirArray);
// loop through the files and add them to the zip file
for($index=0; $index < $indexCount; $index++) {
$file = "{$dirArray[$index]}";
$zip->addFile($file, $file);
}
// close the zip file
$zip->close();
?>
您檢查您有權寫呢?這些函數返回什麼? – Orbling 2011-02-13 18:24:53