![](/img/trans.png)
[英]move_uploaded_file(…): failed to open stream: Permission denied in… Using Mac OS X Mountain Lion
[英]Folder and file permission issues on Mac OS X
我编写了一个PHP脚本,该脚本接受MySQL查询的结果,对结果进行json_encode编码,最后执行file_put_contents()操作。 在PC上运行Bitnami WAMP开发服务器时,脚本可以完美执行。 但是,在Mac上克隆我的git项目时(运行优胜美地)。 尝试执行file_put_contents()函数时,权限被拒绝。 这是我的脚本:
<?php
// All Articles to JSON //
if( array_key_exists("makejson", $_REQUEST) ) {
// Class to Serialize The JSON
class ArrayValue implements JsonSerializable {
public function __construct(array $array) {
$this->array = $array;
}
public function jsonSerialize() {
return $this->array;
}
}
// Designate the file
$file = "articles.json";
// FHA articles query
$milArticles = $dataConnection->SelectColsWhere( "text_news", "active='1' ORDER BY ndate DESC", "textnewsid,ndate,ntitle,sentence" );
if(count($milArticles) > 0){
$json_data = json_encode( new ArrayValue($milArticles), JSON_HEX_APOS | JSON_PRETTY_PRINT );
// Check for JSON errors
if ($json_data === null && json_last_error() !== JSON_ERROR_NONE) {
throw new \LogicException(sprintf("Failed to parse json string '%s', error: '%s'", $json_data , json_last_error_msg()));
} else {
file_put_contents($file, $json_data, LOCK_EX);
}
}
}// END OF MAKE JSON
这是我得到的错误:
[Mon Feb 09 16:06:20.522798 2015] [:error] [pid 686] [client 127.0.0.1:50195] PHP Warning: file_put_contents(articles.json): failed to open stream: Permission denied in /Users/myuser/Sites/PIXEL/militaryinfo/restrict/includes/articleJson.php on line 33, referer: http://militaryinfo/restrict/submit_JSON.php
这是我要写入的目录中的权限:
drwxr-xr-x 15 myuser staff 510 Feb 6 19:13 restrict
我听说的解决方案在PHP和chmod()中运行unmask(),但是我都没有运气。 即使在终端中运行chmod或chown似乎也无济于事。
运行echo exec('whoami');
在PHP
脚本中,然后从浏览器运行PHP脚本。 它给您谁是服务器应用程序的所有者。
然后chown
用户和组中的两个,并根据需要提供适当的权限。 就像是:
chown -R user:user /my/folder
user
从PHP脚本中发现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.