I'm trying to load a file, add some text and then save the file, I have this:
$css = file_get_contents("unzipped/$folder/style.css");
if(file_put_contents("ADD THIS " . $css, "unzipped/$folder/style.css")){
echo("All Done!");
}
and even though 'All Done!' is echoed the contents of the file isn't changing.
Any ideas? :S开发者_高级运维
EDIT:
I also want to add that if I echo $css
the contents of the file is shown correctly
Your parameters are in the wrong order. See the file_put_contents
documentation. Your corrected code:
$css = file_get_contents("unzipped/$folder/style.css");
if(file_put_contents("unzipped/$folder/style.css", "ADD THIS " . $css)){
echo("All Done!");
}
You'll probably notice a file called "ADD THIS " with the contents of that file, as the file name. The contents of the crazily named file will be whatever unzipped/$folder/style.css
would parse out to.
The path to the file is the first argument to 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!");
}
When you use functions that might return a zero as a valid result you should use strict type comparison (===)
if(file_put_contents("ADD THIS " . $css, "unzipped/$folder/style.css") === true){
echo("All Done!");
}
精彩评论