viernes, 22 de septiembre de 2017

php get mp3 file duation

<?php
 $duration=shell_exec("mp3info -p \"%m:%s\n\" $argv[1]");
echo $duration;

?>


 php mp3info.php /var/www/html/dialer/audio/57c081f2de8cd.mp3
0:34
Duration in minutes en seconds


miércoles, 20 de septiembre de 2017

php filters

if (filter_input(INPUT_GET, "num", FILTER_VALIDATE_INT)) {


}


  • Filter Functions
    • filter_has_var — Checks if variable of specified type exists
    • filter_id — Returns the filter ID belonging to a named filter
    • filter_input_array — Gets external variables and optionally filters them
    • filter_input — Gets a specific external variable by name and optionally filters it
    • filter_list — Returns a list of all supported filters
    • filter_var_array — Gets multiple variables and optionally filters them
    • filter_var — Filters a variable with a specified filter
  • http://php.net/manual/en/filter.filters.validate.php
    [0] => int
    [1] => boolean
    [2] => float
    [3] => validate_regexp
    [4] => validate_url
    [5] => validate_email
    [6] => validate_ip
    [7] => string
    [8] => stripped
    [9] => encoded
    [10] => special_chars
    [11] => unsafe_raw
    [12] => email
    [13] => url
    [14] => number_int
    [15] => number_float
    [16] => magic_quotes
    [17] => callback
)
add a note

sábado, 16 de septiembre de 2017

php converting from second to minutes

<?php

$time=9;

if($time>60){
$min=($time/60);

if(is_float($min)){

$min=floor($min);
        $min=($min*60);

$sec=($time-$min);
        $min=($min/60);

        echo " $min:$sec Min";


}


else {
echo "$time Min";
}


}

else {
echo "$time Sec";

}
?>


Function mode

<?php

function minutes($time) {

if($time>60){
$min=($time/60);

if(is_float($min)){

$min=floor($min);
        $min=($min*60);

$sec=($time-$min);
        $min=($min/60);

        return " $min:$sec Min";


}


else {

return "$time Min";
}


}

else {
return "$time Sec";

}

}

?>

echo minute(784);

miércoles, 13 de septiembre de 2017

php download file

<?php
$fname=uniqid();
$attachment_location ="/var/spool/asterisk/monitor/OUT102-20170829-085404-1504022044.824.wav";
        if (file_exists($attachment_location)) {
            header($_SERVER["SERVER_PROTOCOL"] . " 200 OK");
            header("Cache-Control: public"); // needed for internet explorer
            header("Content-Type: application/wav");
            header("Content-Transfer-Encoding: Binary");
            header("Content-Length:".filesize($attachment_location));
            header("Content-Disposition: attachment; filename=$fname.wav");
            readfile($attachment_location);
            die();
        } else {
            die("Error: File not found.");
        }

?>

miércoles, 6 de septiembre de 2017

STDIN & STDOUT


<?php fwrite(STDOUT, "Please enter your namen");

// Read the input
$name = fgets(STDIN);



fwrite(STDOUT, "Hello $name");

// Exit correctly
exit(0);
?>



echo " hello world " | php stdin.php
result  hello world

<?php
//$stdin = fopen('php://stdin', 'r');
$stdin=stream_get_contents(STDIN);
echo $stdin;
?>

Other method

<?php

echo  " This is the result $argv[1]";

?>

a=$(echo 'ambiorix') | php cmd.php $a
 This is the result ambiorix