Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP:file\u put\u内容回显警告_Php - Fatal编程技术网

PHP:file\u put\u内容回显警告

PHP:file\u put\u内容回显警告,php,Php,警告代码: Warning: file_put_contents(#C_H1_container { position:relative; min-height: 200px;} h1 { position: absolute; top: 0; left: 30px; font-size: 4em; color: #000000; } h2 { position: absolute; top: 50px; left: 212px; font-size: 4em; color: #000000;

警告代码:

Warning: file_put_contents(#C_H1_container { position:relative; min-height: 200px;} h1 { position: absolute; top: 0; left: 30px; font-size: 4em; color: #000000; } h2 { position: absolute; top: 50px; left: 212px; font-size: 4em; color: #000000; z-index: 100; } #logo {position: absolute; top: 50px; left: 10px; z-index: 99; max-height: 195px;} #topright_link { position: absolute; top: 0; right: 20px; background: #423231; } #topright_link ul { font-size: .95em; line-height: .95em; margin: 0; padding: 0; list-style: none; } #topright_link ul li { display: block; position: relative; float: left; } #topright_link ul li a { display: block; text-decoration: none; color: #fff; padding: 11px 25px; white-space: nowrap; text-align: center; text-decoration: none; font-weight: bold; min-width: 100px; } #topright_link ul li a:hover { background: #1e7c9a; color: #fff; } #topright_link li:hover a { background: #CCC; color: #000; } #navigation { position: absolute; top: 140px; left: 0; right: 0; width: 100%; height: 45px; backgr in /home/kylej/public_html/style.php on line 13
代码

$stylesheet_original = file_get_contents('www.domain.com/stylesheet.css');
$stylesheet_new = $_POST['stylesheet'];

if (isset($_POST['stylesheet'])) { 
file_put_contents($stylesheet_original, $stylesheet_new);
}

echo '
<form action="style.php" method="POST">
<textarea name="stylesheet" style="width: 700px; height: 300px;">'. $stylesheet_original .'</textarea>
<input type="submit">
</form>
';
$stylesheet\u original=file\u get\u contents('www.domain.com/stylesheet.css');
$stylesheet_new=$\u POST['stylesheet'];
如果(isset($_POST['stylesheet']){
文件内容($stylesheet\u original,$stylesheet\u new);
}
回声'
“.$stylesheet_原件”
';
我以前从未真正使用过文件内容,通过谷歌搜索我的问题也找不到任何东西。我只是测试一下是否能够编辑文件中文本区域的内容并保存回文件。如果有更好的方法,请分享

提前谢谢

改变这一点:

if (isset($_POST['stylesheet'])) { 
  file_put_contents($stylesheet_original, $stylesheet_new);
}
为此:

if (isset($_POST['stylesheet'])) { 
  file_put_contents( $_SERVER['DOCUMENT_ROOT'].'/stylesheet.css', $stylesheet_new);
}

接受文件名作为第一个参数。您有一个变量,其中包含我们要替换的文件的内容。

它现在正在处理。这是一次疏忽,谢谢你的注意。你能告诉我它为什么抛出这个错误吗:
警告:file\u put\u contents(…stylesheet.css…):无法打开流:HTTP包装器不支持第14行的/home/***/public\u html/stylesheet.css中的可写连接
@kdjernigan你的错误是因为“www.domain.com/stylesheet.css”是一个网址,而不是本地文件路径。如果www.domain.com是php正在执行的同一个网站,您可以将“www.domain.com/stylesheet.css”替换为$_SERVER['DOCUMENT\u ROOT']./stylesheet.css“非常欢迎您,信誉积分第一次超过500,谢谢。