drl6054
drl6054
采纳率0%
2011-07-27 00:53 浏览 310
已采纳

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

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

3条回答 默认 最新

  • 已采纳
    doutou7961 doutou7961 2011-07-27 00:56

    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!"); 
    }
    
    点赞 评论 复制链接分享
  • duandou8120 duandou8120 2011-07-27 00:55

    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.

    点赞 评论 复制链接分享
  • dtxooq1020 dtxooq1020 2011-07-27 00:59

    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!"); 
    }
    
    点赞 评论 复制链接分享

相关推荐