简体   繁体   English

PHP:file_put_content回显警告

[英]PHP: file_put_content echoing out warning

Warning Code: 警告代码:

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

The Code 编码

$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>
';

I have never really used file_put_contents before, and I can't find anything by googling my issue. 我以前从未真正使用过file_put_contents,通过谷歌搜索我的东西也找不到任何东西。 I'm just testing out being able to edit content in a textarea from a file and saving back to file. 我只是在测试是否可以从文件编辑文本区域中的内容并将其保存回文件。 If there is a better way, please share. 如果有更好的方法,请分享。

Thanks in advance! 提前致谢!

Change This: 更改此:

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

To this: 对此:

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

file_put_contents accepts a file name as the first parameter. file_put_contents接受文件名作为第一个参数。 You had a variable which contains the contents of the file we are replacing. 您有一个变量,其中包含我们要替换的文件的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM