PHP file_put_contents没有保存,但没有显示错误/警告

Lee*_*ice 0 php

我正在尝试加载文件,添加一些文本然后保存文件,我有这个:

$css = file_get_contents("unzipped/$folder/style.css");
if(file_put_contents("ADD THIS " . $css, "unzipped/$folder/style.css")){
   echo("All Done!"); 
}
Run Code Online (Sandbox Code Playgroud)

即使'完成!' 被回应的文件内容没有变化.

有任何想法吗?:S

编辑:

我还想补充一点,如果我回$css显文件的内容是正确显示的

Cyc*_*one 12

您的参数顺序错误.请参阅file_put_contents文档.您更正后的代码:

$css = file_get_contents("unzipped/$folder/style.css");
if(file_put_contents("unzipped/$folder/style.css", "ADD THIS " . $css)){
   echo("All Done!"); 
}
Run Code Online (Sandbox Code Playgroud)

您可能会注意到一个名为"ADD THIS"的文件,其中包含该文件的内容,作为文件名.疯狂命名文件的内容将是unzipped/$folder/style.css解析出来的内容.


pro*_*son 7

文件的路径是第一个参数file_put_contents.

$css = file_get_contents("unzipped/$folder/style.css");
if(file_put_contents("unzipped/$folder/style.css", "ADD THIS " . $css)){
   echo("All Done!"); 
}
Run Code Online (Sandbox Code Playgroud)