无法在php中创建目录

无法在php中创建目录,php,rss,Php,Rss,我试着用php文件读取rss提要并缓存它。 我将源代码复制并粘贴到我自己的项目中。我正在Mac OS X安装上使用XAMPP 资料来源如下: 首先,我不能用mkdir创建目录。它说许可被拒绝 其次,$feed=file\u get\u contents($path,true)未返回php对象。我的意思是当我用如果(is_object($feed)&&&$feed->query->count)检查它时,我无法通过。 最后,我不能$cachefile=fopen($cache,'wb') <?

我试着用php文件读取rss提要并缓存它。 我将源代码复制并粘贴到我自己的项目中。我正在Mac OS X安装上使用XAMPP

资料来源如下:

首先,我不能用mkdir创建目录。它说许可被拒绝
其次,
$feed=file\u get\u contents($path,true)未返回php对象。我的意思是当我用
如果(is_object($feed)&&&$feed->query->count)
检查它时,我无法通过。
最后,我不能
$cachefile=fopen($cache,'wb')

<?php

$cache = dirname(__FILE__) . "/cache/feed";
echo filemtime($cache);
if(filemtime($cache))
{
   // Get from server
   if ( !file_exists(dirname(__FILE__) . '/cache') ) {
      mkdir(dirname(__FILE__) . '/cache', 0777);
   }
   // YQL query (SELECT * from feed ... ) // Split for readability
   $path = "http://query.yahooapis.com/v1/public/yql?q=";
   $path .= urlencode("SELECT * FROM feed WHERE url='http://feeds.hindustantimes.com/HT-HomePage-TopStories'");
   $path .= "&format=json";

   // Call YQL, and if the query didn't fail, cache the returned data
   $feed = file_get_contents($path, true);
   print_r($feed);

   // If something was returned, cache
   if ( is_object($feed) && $feed->query->count ) {
      $cachefile = fopen($cache, 'wb');
      fwrite($cachefile, $feed);
      fclose($cachefile);
      echo 'writing to disk';
   }
}
else
{
   // We already have local cache. Use that instead.
   $feed = file_get_contents($cache);
}

// Decode that shizzle
$feed = json_decode($feed);

print_r($feed);
// Include the view
//include('views/site.tmpl.php');

?>

非常确定XAMPP是以“nobody”用户的身份运行的,因此您必须为希望可写的目录授予“nobody”权限:

chown nobody:nobody dir_in_question

请记住,XAMPP是一个很棒的开发服务器,但它不是现成的安全服务器,所以在生产中使用它时要小心。有关相关问题,请参阅。

如果
mkdir
不起作用,则需要对目录进行chmod,以允许web服务器在本地主机上创建目录、文件等。已完成chmod 777 HTDOC