PHP File_put_contents not working

℡╲_俬逩灬. 提交于 2019-11-30 10:01:27

问题


Check this code:

<?php

$url = 'http://www.example.com/downloads/count.txt';

$hit_count = @file_get_contents($url);
$hit_count++;
@file_put_contents($url, $hit_count);

header('Location: wmwc.zip');

?>

@file_get_contents is working fine and the header location change to the downloaded file also works, but either the hit_count increase or @file_put_contents isn't working, because the number with the file doesnt increase by 1. I've set the file permission to 777, but when I try to set the directory permission to 777 also I get a 500 internal server error saying "The server encountered an unexpected condition which prevented it from fulfilling the request."


回答1:


You can't write a remote file via http.(If you could do that, every one else could change that file also.)

You need to use the local path.




回答2:


try changing directory properties

chown www-data:www-data <dirname>

and/or write as follows, if you host on linux

<?php
$var ="hi";
shell_exec('echo "'.$var.'">>log.txt');
?>


来源:https://stackoverflow.com/questions/12211677/php-file-put-contents-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!