我试图压缩它调用的文件夹
Maker_100164在这个文件夹里面有两个文件夹和两个文件
folder_a
folder_b
index1.php
的index.php
我正在使用以下功能
function Zip($source, $destination)
{
if (!extension_loaded('zip') || !file_exists($source)) {
return false;
}
$zip = new ZipArchive();
if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
return false;
}
$source = str_replace('\\', '/', realpath($source));
if (is_dir($source) === true)
{
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
foreach ($files as $file)
{
$file = str_replace('\\', '/', $file);
// Ignore "." and ".." folders
if( in_array(substr($file, strrpos($file, '/')+1), array('.', '..')) )
continue;
$file = realpath($file);
if (is_dir($file) === true)
{
$zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
}
else if (is_file($file) === true)
{
$zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
}
}
}
else if (is_file($source) === true)
{
$zip->addFromString(basename($source), file_get_contents($source));
}
return $zip->close();
}
当我想打电话时,我称之为
$dirp = '/maker/up/users/admin/Maker_100164/';
$p = '/maker/up/users/admin/Maker_100164/Maker_100164.zip';
$zipallfolders = Zip($dirp, $p);
if($zipallfolders)
{
echo 'ok';
}else{
echo 'wrong';
}
但它没有用。