私はZIPSディレクトリのスクリプトを持っていますが、* .phpファイルも追加する必要があります。RecursiveIteratorIterator:zip内のディレクトリとphpファイルを含む
../index.phpのようなものを追加すると、エラーが発生します。以下のスクリプトによって生成さ
エラーは次のとおりです。
Fatal error: Uncaught exception 'UnexpectedValueException' with message 'RecursiveDirectoryIterator::__construct(../index.php): failed to open dir: Not a directory' in /home/mathtest/public_html/trig/admin/save.php:23 Stack trace: #0 /home/mathtest/public_html/trig/admin/save.php(23): RecursiveDirectoryIterator->__construct('../index.php') #1 {main} thrown in /home/mathtest/public_html/trig/admin/save.php on line 23
は私のスクリプト:
<?php
/* CONFIG */
$pathToAssets = array("../images", "../Data", "../css", "../index.php");
$filename = "temp/backup.zip";
/* END CONFIG */
$zip = new ZipArchive();
$zip->open($filename, ZipArchive::CREATE);
//add folder structure
foreach ($pathToAssets as $thePath) {
// Create recursive directory iterator
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($thePath), RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $name => $file) {
if ($file->getFilename() != '.' && $file->getFilename() != '..') {
// Get real path for current file
$filePath = $file->getRealPath();
$temp = explode("/", $name);
array_shift($temp);
$newName = implode("/", $temp);
// Add current file to archive
$zip->addFile($filePath, $newName);
}
}
}
$zip->close();
$yourfile = $filename;
$file_name = basename($yourfile);
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: Binary");
header("Content-Disposition: attachment; filename=$file_name");
header("Content-Length: " . filesize($yourfile));
readfile($yourfile);
unlink('temp/backup.zip');
exit;
?>
私は解決で運なしでここにも多くの質問をhttp://php.net/manual/en/class.recursiveiteratoriterator.phpでRecursiveIteratorIteratorについて読んでてきました。
../index.phpをjust ../と置き換えるが、zipに入れたくないディレクトリも含む。
ダウンロードしたzipにPHPを挿入できるようにするための入力があれば幸いです。
RecursiveDirectoryIteratorは、スキャンするディレクトリのみを使用します。したがって、ファイルを別々に扱わなければならない場合もあれば、イテレーターをインクルードファイルにも適合させることができるかもしれません。 Thriaultによるhttps://secure.php.net/manual/en/class.recursivedirectoryiterator.phpの最初のコメントは、PHPファイルを扱います。 – jedifans
ありがとう@jedifans。私はそのb4の投稿を試みましたが、動作しませんでした。 zipファイルにphpファイルがないので、私のスクリプトに正しく適合していない可能性があります。 – Woody