3v4l.org

run code in 300+ PHP versions simultaneously
<?php // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $vmDir = '/var/spool/asterisk/voicemail/especial'; $idCustomer = $_SESSION['user_data']['id']; $vmCustomer = $vmDir . '/' . $idCustomer; $req = $_REQUEST['c']; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if(in_array($req, array('get', 'del'))) { switch($req) { /** * Ruta para listar mensajes de voz */ case 'get_list': $newVmList = $oldVmList = array(); $response = array(); $index = 0; /* nuevos mensajes de voz */ chdir($vmCustomer . '/INBOX'); array_multisort(array_map('filemtime', ($newVmList = glob("*.txt"))), SORT_DESC, $newVmList); /* archivo mensajes de voz */ chdir($vmCustomer . '/Old'); array_multisort(array_map('filemtime', ($oldVmList = glob("*.txt"))), SORT_DESC, $oldVmList); foreach($newVmList as $file) { $response[$index] = parseVmInfoFile($file, true); $response[$index]['new'] = true; $index++; } foreach($oldVmList as $file) { $response[$index] = parseVmInfoFile($file, false); $response[$index]['new'] = false; $index++; } echo json_encode($response); break; /** * Ruta que se ejecuta para recuperar el fichero de audio * del mensaje y mover los mensajes nuevos al directorio * de archivo */ case 'play': $vmInfo = $_GET['vm_info']; $wavFile = $vmCustomer . '/' . ($new ? 'INBOX' : 'Old') . '/' . basename($vmInfo['file'], '.txt') . '.wav'; $fh = fopen($wavFile, 'rb'); header("Content-Type: audio/wav"); header("Content-Length: " . filesize($wavFile)); fpassthru($fh); break; /** * Ruta para eliminar un mensaje de voz */ case 'del': $vmInfo = $_GET['vm_info']; $txtFile = $vmCustomer . '/' . ($new ? 'INBOX' : 'Old') . '/' . $vmInfo['file']; $wavFile = $vmCustomer . '/' . ($new ? 'INBOX' : 'Old') . '/' . basename($vmInfo['file'], '.txt') . '.wav'; unlink($txtFile); unlink($wavFile); break; } } /** * Parsea la informaciĆ³n contenida en el fichero de txt * asociado al mensaje de voz * * @param string $file Nombre del fichero * @param boolean $new Nuevo mensaje de voz (true) o de * archivo * @return array */ function parseVmInfoFile($file, $new) { $path = $vmCustomer . '/' . ($new ? 'INBOX' : 'Old'); $vmInfo = parse_ini_file($path . '/' . $file); return array( 'callerid' => $vmInfo['callerid'], 'date' => new \DateTime($vmInfo['origdate']), 'duration' => (int)$vmInfo['duration'], 'file' => $file ); }

preferences:
48.52 ms | 402 KiB | 5 Q