Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP文件\u放置\u内容不工作_Php_File Permissions_Directory Permissions - Fatal编程技术网

PHP文件\u放置\u内容不工作

PHP文件\u放置\u内容不工作,php,file-permissions,directory-permissions,Php,File Permissions,Directory Permissions,检查此代码: <?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\u get\u contents工作正常,下载文件的标题位置更改也正常,但命中计数

检查此代码:

<?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\u get\u contents
工作正常,下载文件的标题位置更改也正常,但命中计数增加或
@file\u put\u contents
不起作用,因为文件的数字没有增加1。我已将文件权限设置为777,但当我尝试将目录权限设置为777时,我还收到一个500内部服务器错误,表示“服务器遇到意外情况,无法满足请求。”

您无法通过http编写远程文件。(如果您可以这样做,其他人也可以更改该文件。)


您需要使用本地路径。

尝试更改目录属性

chown www-data:www-data <dirname>
chown www数据:www数据
和/或如果您在linux上运行,请按以下方式编写

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

拿走@并告诉我们您遇到了什么错误。@隐藏错误。您试图写入url。我认为这不应该与
http
一起使用。也许您想编写一些本地文件,但是您必须使用该文件的路径。删除@并得到以下结果:无法打开流:http包装器没有在目录权限为755.777的第7行中,不支持/hermes/bosweb/web046/b462/glo.ckrsavonte/whoolimooli/downloads/index.php中的可写连接。我使用的是wordpress,因此URL实际上并不指向系统的根。因为它是php,我假设路径必须是相对的e指向执行此函数的php文件是的,而不是页面的实际URL。这是否正确?@CoreyRS最好使用绝对路径。好吧,那么我想你误解了我最初的帖子。我在变量中设置的URL是绝对路径,该文件托管在我的本地服务器上,但它仍然不工作。@CoreyRS我不是指http路径,我是指服务器中的文件路径,使用类似
/wwwroot/downloads/count.txt
@CoreyRS Error msg将告诉您原因。