【问题标题】:Writing text to a file on site with php [closed]使用php将文本写入站点上的文件[关闭]
【发布时间】:2015-02-03 14:41:17
【问题描述】:

我是 PHP 新手,我想将文本写入 .html 文件我想将数据写入 URL,例如 http://anyurl.com/path/page.html 代码如下。

$file = "http://anyurl.com/path/page.html";
$text = "Hello world";
file_put_contents($file, $text);

但是没有成功 我做错了什么?

【问题讨论】:

  • 但没有成功 这是什么意思?你有任何错误吗?
  • 不,我没有收到任何错误,但是当我打开要插入数据的文件时,它仍然是空白的。
  • 在文件顶部添加错误报告:<?php ini_set("display_errors", 1); error_reporting(E_ALL); ?>,然后告诉我们错误
  • 您不能使用 http 协议写入文件。它必须是文件协议。使用像 /server/file/path 这样的绝对路径。如果有人可以使用 http 协议写入文件,那么我将重写 www.facebook.com 上的文件

标签: php


【解决方案1】:

试试这个..它可以正常工作:)

<?php

$myfile = fopen("newfile.html", "w") or die("Unable to open file!");

$txt = "John Doe\n";

fwrite($myfile, $txt);

$txt = "Jane Doe\n";

fwrite($myfile, $txt);

fclose($myfile);
?> 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-14
    • 1970-01-01
    • 1970-01-01
    • 2017-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多