drls2738 2015-08-03 12:02
浏览 18

创建/附加数据到Web服务器文件

First of all I am a novice client side only HTML person. I run a web site which has results that need to be uploaded every week. To simplify the addition of a new line I have created a file that is then included into the main html file as follows (let's call it results.htm):

<br><a href="R20150729.htm">27 Jul 2015</a>
<br><a href="R20150722.htm">22 Jul 2015</a>
-----
-----
<br><a href="R20150715.htm">15 Jul 2015</a>

Every week I (or colleagues) have to log onto the host and edit the file manually to add the extra line at the top.

(The reason it is such a basic file and uses an iframe to embed code is that some people find it difficult to find the correct line and modify it when there is a lot of HTML in the file.)

The Ryyyymmdd.htm can easily be uploaded using FTP and I am now trying to avoid having to log on and modify results.htm

One way I had thought of doing this is to create todays results e.g.
<a href="R201508.03.htm">03 AUG 2015</a>

This can be done easily with a text editor on the local PC. It can then be uploaded as for example, recent.txt I then need to add recent.txt to the front of results.htm. I guess appending results.htm to recent.txt then renaming results.htm as resultsold.htm and renaming recent.txt (which now has all the lines) to results.htm would give me

<br><a href="R20150803.htm">03 Aug 2015</a>
<br><a href="R20150729.htm">27 Jul 2015</a>
<br><a href="R20150722.htm">22 Jul 2015</a>
-----
-----
<br><a href="R20150715.htm">15 Jul 2015</a>

What I want to avoid is downloading results.htm, adding a line at the beginning and then uploading it.

Ideas and or some code would be appreciated. I am using Filezilla as my FTP The crunch is to try and get everything automated so a click of a button can do it all and avoid logging into the web server and modify the line manually. If it can be done by messing around in the FTP program, or if REALLY necessary some server side code (I have not done this before).

Thanks.

  • 写回答

1条回答 默认 最新

  • dsw1608 2015-08-03 12:22
    关注

    Save this file as "add_new_result.php" in the same folder with "results.htm". And navigate your browser to "www.domain.com/add_new_result.php" (if it is in a sub-folder you must navigate to correct place). And try writing the input and clicking "Add New Result" button.

    <?php
    if(isset($_POST['field1'])) {
        $data = $_POST['field1'] . "
    ";
        $ret = file_put_contents('results.htm', $data, FILE_APPEND | LOCK_EX);
        if($ret === false) {
            die('There was an error writing this file');
        }
        else {
            echo "$ret bytes written to file";
        }
    }
    else {
    ?>
    <html>
    <head>
        <title>Add New Result</title>
    </head>
    <body>
    <form action="add_new_result.php" method="POST">
        <input name="field1" type="text" style="min-width:300px;"/>
        <input type="submit" name="submit" value="Add New Result">
    </form>
        <a href='data.txt'>Text file</a>
    </body>
    <? } ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了