Here’s the source for a php/agi file and dialplan sample I made, which can help you implement what you need :
#extensions.conf
exten => 12345,1,Goto(dtmf-recording,${EXTEN},1)
[dtmf-recording]
exten => _X.,1,Answer
exten => _X.,2,Set(TIMEOUT(digits)=5)
exten => _X.,3,Set(TIMEOUT(response)=10)
exten => _X.,4,Set(TIMESTAMP=${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)})
exten => _X.,n,Read(DTMF|/var/lib/asterisk/agi-bin/sounds/whatever)
exten => _X.,n,Hangup
exten => h,1,Deadagi(agi-bin/report_dtmf.php|${TIMESTAMP}|${DTMF})
—————————————————
report_dtmf.php :
<?php
set_time_limit(30);
require_once “phpagi.php”;
declare(ticks = 1);
ob_implicit_flush(true);
$AGI = new AGI();
$DSTDIR = “/var/lib/asterisk/agi-bin/recordings/”; //Folder where you want to store the file.
$CALLERID = $AGI->request[‘agi_callerid’];
$DATE = $_SERVER[“argv”][1];
$DTMF = $_SERVER[“argv”][2];
$contents = ”
Caller ID: $CALLERID
DTMF: $DTMF
Date: $DATE
“;
$fp = fopen($DSTDIR.$recfile.’.txt’, ‘w’);
fwrite($fp, $contents);
fclose($fp);
?>