Попытка собрать большой html-документ с вводом из формы

Я пытаюсь построить документ из его различных частей. Целевой документ не получает никакого содержимого.

Можете ли вы сказать мне, что я делаю неправильно здесь?

У меня есть begin.txt с содержимым HTML и end.txt, в начало которого я хочу добавить новый код (newarticle.txt), чтобы он перемещался вперед каждый раз, когда делается новое дополнение. Затем я хочу, чтобы все это было собрано в articles.html.

<?php
$v1 = $_POST["url"]; //You have to get the form data
$v2 = $_POST["description"];
$v3 = $_POST["date"];

$destination = fopen('articles.html', 'w+');
$begin = fopen('begin.txt','w+');
$end = fopen('end.txt','w+');
$currentend = file_get_contents('/end.txt');
$currentbegin = file_get_contents('/begin.txt');

$file = fopen('newarticle.txt', 'w+'); //Open your .txt file
ftruncate($file, 0); //Clear the file to 0bit
// $content =  <li><a href=$v1. PHP_EOL .$v2. PHP_EOL .$v3;

$build1 = <<<EOF
<li><a href="$v1">$v2</li>
<li>$v3</li>
EOF;

fwrite($file , $build1); //Now lets write it in there
fclose($file ); //Finally close our .txt

$file = "newarticle.txt";
$currentfile = file_get_contents($file);

$build2 = <<<EOF
$build1
$currentend
EOF;

ftruncate($end, 0); //Clear the file to 0bit
fwrite ($end , $build2);
fclose ($end );

$updatedend = 'end.txt';
$updatedendcontent = file_get_contents($updatedend);
ftruncate($destination, 0);

$build3 = <<<EOF
$currentbegin
$updatedendcontent
EOF;

fwrite ($destination , $build3);
fclose ($destination );
die(header("Location: ".$_SERVER["HTTP_REFERER"]));
?>

Исправил, это работает

<?php
$v1 = $_POST["url"]; //You have to get the form data
$v2 = $_POST["description"];
$v3 = $_POST["date"];

// $begin = fopen('begin.txt','w+');
$currentend = file_get_contents('end.txt');
$currentbegin = file_get_contents('begin.txt');

$file = fopen('newarticle.txt', 'w+'); //Open your .txt file
ftruncate($file, 0); //Clear the file to 0bit
// $content =  <li><a href=$v1. PHP_EOL .$v2. PHP_EOL .$v3;

$build1 = <<<EOF
<li><a href="$v1">$v2</li>
<li>$v3 by Accounting Today</li>
EOF;

fwrite($file , $build1); //Now lets write it in there
fclose($file ); //Finally close our .txt

//$file = "newarticle.txt";
$currentfile = file_get_contents('newarticle.txt');

$build2 = <<<EOF
$build1
$currentend
EOF;

$end = fopen('end.txt','w+');
ftruncate($end, 0); //Clear the file to 0bit
fwrite ($end , $build2);
fclose ($end );

//$updatedend = 'end.txt';
$updatedendcontent = file_get_contents('end.txt');


$build3 = <<<EOF
$currentbegin
$updatedendcontent
EOF;

$destination = fopen('articles.html', 'w+');
ftruncate($destination, 0);
fwrite ($destination , $build3);
fclose ($destination );
die(header("Location: ".$_SERVER["HTTP_REFERER"]));
?>

person John MacKenzie    schedule 01.02.2019    source источник
comment
Я не уверен, что это сработает, но сначала вы делаете $end = fopen('end.txt','w+');, чем используете обработчик для $currentend = file_get_contents($end);. Я не знаю, будет ли это работать таким образом. Конечно, вы можете передать расположение файла, например file_get_contents('/path/to/your/file.txt. Только не уверен, что он может работать с обработчиками от fopen.   -  person Volmarg Reiso    schedule 01.02.2019
comment
Используя ваши инструкции, теперь он создает начальный элемент, который входит в newarticle.txt, но не добавляется к end.txt, он просто содержит тот же текст, что и newarticle.txt, и обновляется каждый раз, очищая файл, а не добавляя содержимое в начало end.txt, чтобы оно двигалось вперед   -  person John MacKenzie    schedule 14.02.2019
comment
Так что не уверен, был ли это мой порядок предметов или то, что предложил Вольмарг, и мой заказ. но я исправил.   -  person John MacKenzie    schedule 14.02.2019