2012-01-31 102 views
0

我正在尝试使用这个tutorial读取RSS文件并使用php文件进行缓存。 我将源复制并粘贴到我自己的项目中。我在Mac OS X安装上使用XAMPP。无法在php中创建目录

这里是源:

首先,我不能用mkdir目录。它说权限被拒绝。
二,$feed = file_get_contents($path, true);没有返回一个php对象。我的意思是当我用if (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'); 

?> 
+2

如果'mkdir'不工作,那么你需要在目录上chmod以允许你的web服务器创建目录,文件等。 – 2012-01-31 19:48:48

+0

在localhost上执行此操作。已经完成chmod 777 htdocs – amit 2012-01-31 19:53:29

回答

1

很肯定XAMPP运行的“无人”用户,这样你将不得不放弃“没有人”的权限,你想成为可写目录:

chown nobody:nobody dir_in_question 

请记住,XAMPP是一个出色的开发者服务器,但不是开箱即用的安全解决方案,所以在生产中使用它时要小心。有关相关问题,请参阅this article