开发者

Is there a way to use file_put_contents() and store the cached contents in a different directory?

I am able to put the file content开发者_Python百科s if I stay in the same directory level

ie: `file_put_contents('cache.txt', $result);

But how would I put the contents up a folder, or even two? Adding '../cache/cache.txt' does not seem to work.`


That would work fine assuming the user the web server runs as has write permission to that directory.


Try using the direct path of where you would like to put the cache content.

<?php
$file = 'people.txt';
$cacheFile = __FILE__  . '/cache/'. $file;

$content = 'Something';

file_put_contents($file, $content);
file_put_contents($cacheFile, $content);

?>

Assuming you have a folder called cache, with write permissions to it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜