简体   繁体   English

PHP File_put_contents无法正常工作

[英]PHP File_put_contents not working

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." @file_get_contents正常工作,并且将标题位置更改为下载文件也可以,但是hit_count增加或@file_put_contents均不起作用,因为文件的数量没有增加1。我将文件许可权设置为777 ,但是当我尝试将目录权限设置为777时,我也收到500个内部服务器错误,提示“服务器遇到意外情况,阻止其满足请求。”

You can't write a remote file via http .(If you could do that, every one else could change that file also.) 您无法通过http写入远程文件 。(如果可以这样做,其他所有人也可以更改该文件。)

You need to use the local path. 您需要使用本地路径。

try changing directory properties 尝试更改目录属性

chown www-data:www-data <dirname>

and/or write as follows, if you host on linux 如果您在Linux上托管,则如下所示:

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

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

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