douxian3170 2018-12-11 19:37
浏览 50

将php网页发送到文件夹并将内容显示为html

would it be possible to have a html/php template on index.php say for example (a news webpage template and then anyone can edit the title, paragraphs only, then on submit it then sends the webpage with the data stored to a paste bin like url so who ever visits that url say http://localhost/news/jjeh3bndjks they would only be able to view to content and not edit.

I would like to use something like this

<?php
if ($_POST) {
    $pasteID = uniqid();
    $paste = fopen("pastes/".$pasteID.".php", "w");
    $contents = $_POST['pasteContents'];
    fwrite($paste, $contents);
    header('Location: /pastes/'.$pasteID.'.php');
}
?>

<form action="" method="POST">
  <input type="text" name="pasteContents" placeholder="write here" />
  <button type="submit" tabindex="0">submit</button>
</form>

but for some reason when i add another input box or try to send anymore data it fails or just gives me the last input given is there a way to send a whole page this way?

any help would be appreciated

  • 写回答

1条回答 默认 最新

  • douhai9043 2018-12-16 10:06
    关注

    You can use file_get_contents with the following code:

    <?php
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    
        parse_str(file_get_contents('php://input'));
        echo param1 . '<br />' . param2;
    } else {
    ?>
    
    <form method="post">
        <input type="text" name="param1" value="param1" />
        <input type="text" name="param2" value="param2" />
        <input type="submit" value="submit" />
    </form>
    <?php } ?>
    

    (You can test it here)

    Although, I did success to use $_POST too:

    <?php
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {    
        echo $_POST['param1'] . '<br />' . $_POST['param2'];
    } else {
    ?>
    
    <form method="post">
        <input type="text" name="param1" value="param1" />
        <input type="text" name="param2" value="param2" />
        <input type="submit" value="submit" />
    </form>
    <?php } ?>
    

    Here

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100