簡體   English   中英

Mac OS X上的文件夾和文件權限問題

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM