ファイルをアップロードする(この場合はzip)には「PHP Simple HTML DOM Parser」を使用し、インデックスファイルを開き、リンクを変更できるようにします。リンクが更新されると、インデックスファイルが上書きされ、ダウンロード用に圧縮されます。HTMLで保存した後に空白を残すSimple Dom Parser
これはすべてうまくいきます。唯一の問題は、更新されたインデックスファイルが保存されると、ファイル内の空白がすべて失われることです。そのため、テキストエディタでファイルを開くと、構造体がレイアウトされなくなり、通常の読み込み/編集が非常に難しくなります。
この空白を保存する方法はありますか?
、アップロードされたファイルを受け取り、ファイルを「アップロード」既存のリンクを表示するには、その下のフィールドにiFrameの中でそれを表示し、それらを更新するためのフィールド:
<div class="output">
<form action="download.php" id="urlform" method="POST">
<?php
//Traverse DOM of iFrame content, output existing href tags
$html = file_get_html($_SESSION['index']);
$i = 1;
$inc = 1;
foreach($html -> find('a') as $element) : ?>
<!-- Ignore untagged links -->
<?php if (strpos($element -> href, "utm") !== false) {
$element -> name = $inc; ?>
<?php if ($i % 2 === 0) {
echo '<div class="alternate">';
} else {
echo '<div class="standard">';
} ?>
<!-- Add name attr to anchor tags for reference -->
<div class="assign">
<p><?php echo $element -> name; ?></p>
</div>
<div class="content">
<h3>Existing tag:</h3>
<p><?php echo $element -> href; ?></p>
<h3>New tag:</h3>
<input type="textarea" name="urltag_<?php echo $inc; ?>">
</div>
</div>
<?php $i++; $inc++; } ?>
<?php endforeach; ?>
<input type="submit" value="Update eShot">
</form>
</div>
、ダウンロードファイル、ショー更新されたインデックスファイルとダウンロードされたiFrame:
<?php
//Open index.html of zip and replace href with new tags
$newhtml = file_get_html($_SESSION['index']);
$inc = 1;
foreach($newhtml -> find('a') as $url) {
if (strpos($url -> href, "utm") !== false) {
$url -> href = $_POST["urltag_" . $inc];
$inc++;
};
}
//Store changes in new index file
file_put_contents($_SESSION['index'], $newhtml);
$folder = $_SESSION['new_directory'];
if (isset($_SESSION['portal'])){
$zipname = $_SESSION['name'] . " " . $_SESSION['portal'] . " " . date('dmy') . ".zip";
} else {
$zipname = $_SESSION['name'] . " " . date('dmy') . ".zip";
}
class FlxZipArchive extends ZipArchive {
public function addDir($folder, $zipname) {
$this->addEmptyDir($zipname);
$this->addDirDo($folder, $zipname);
}
private function addDirDo($folder, $zipname) {
$zipname .= '/';
$folder .= '/';
$dir = opendir ($folder);
while ($file = readdir($dir))
{
if ($file == '.' || $file == '..') continue;
$do = (filetype($folder . $file) == 'dir') ? 'addDir' : 'addFile';
$this->$do($folder . $file, $zipname . $file);
}
}
}
$za = new FlxZipArchive;
$res = $za->open($folder . "/" . $zipname, ZipArchive::CREATE);
if($res === TRUE)
{
$za->addDir($folder, basename($folder));
$za->close();
}
else { echo 'Could not create a zip archive';}
?>
<div class="thankyou">
<p>Thank you. Please check your new links in the eShot below:</p>
</div>
<iframe class="eshotwrapper" src="<?php echo $_SESSION['index'] ?>"></iframe>
<div class="downloadlink">
<p>Once you have confirmed your tagged links are correct, please click the link below to download your new eShot: <br>
(Right-click and select "Save as..." to choose a save location)</p>
<a href="<?php echo $_SESSION['new_directory'] . "/" . $zipname ?>"><button type="button">Download</button></a>
</div>
</div>
ありがとう!