Trying to piece together a large html document with input from a form

帅比萌擦擦* 提交于 2019-12-11 16:16:45

问题


I'm trying to build a document out of its various parts. Destination document does not get any content.

Can you possibly tell me what I'm doing wrong here ?

I have a begin.txt with HTML content and an end.txt which I want to keep having the new code (newarticle.txt) added to the beginning of so it flows forward every time a new addition is made. Then I want it all put together into 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"]));
?>

Fixed it, this works

<?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"]));
?>

来源:https://stackoverflow.com/questions/54473156/trying-to-piece-together-a-large-html-document-with-input-from-a-form

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!