문제

I almost can't write php, and sorry if the question is silly.

This script generates text files like "2013-12-06_192.0.2.0.txt".
I want to change the behavior to generate text files in date folder. (for example, "./2013-12-06/192.0.2.0.txt") How can I do this?

<?php
header('Access-Control-Allow-Origin: *');
header("Content-type: text/html; charset=UTF-8");
mb_language("Japanese");
mb_internal_encoding("UTF-8");
$key=$_POST['key'];
$today = date("Y-m-d");
$logfile=$today."_".$_SERVER['REMOTE_ADDR'].".txt";
$fp = fopen($logfile, "a");
fwrite($fp, $key);
fclose($fp);
?>
도움이 되었습니까?

해결책

You need to create the sub folder first.

// create sub directory (if not already existing)
if(!is_dir($today)) {
    mkdir($today);
}
// logfile path points to the subdirectory
$logfile=$today. "/" . $_SERVER['REMOTE_ADDR'].".txt";
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top