domingo, 30 de julio de 2017

curl test example post and get

curl -G -d"name=ambiorix&lastname=rodriguez" http://45.32.165.238/curl.php

repose for GET

<hr> Get request<br>Array
(
    [name] => ambiorix
    [lastname] => rodriguez
)


reponse for post

 curl  -d"name=ambiorix&lastname=rodriguez" http://45.32.165.238/curl.php
 Post request<br>Array
(
    [name] => ambiorix
    [lastname] => rodriguez
)


sample code

<?php
if($_POST){

echo " Post request<br>";
print_r($_POST);
}
echo "<hr>";
if($_GET){
echo " Get request<br>";

print_r($_GET);
}
?>

POSTing Form Data with cURL

Start your cURL command with curl -X POST and then add -F for every field=value you want to add to the POST:

curl -X POST -F 'username=davidwalsh' -F 'password=something' http://domain.tld/post-to-me.php
If you were using PHP, you could use print_r on the $_POST variable to see that your server received the POST data as expected:
Array(
  'username' => 'davidwalsh',
  'password' => 'something'
)
If you need to send a specific data type or header with cURL, use -H to add a header:
# -d to send raw data
curl -X POST -H 'Content-Type: application/json' -d '{"username":"davidwalsh","password":"something"}' http://domain.tld/login

POSTing Files with cURL

POSTing a file with cURL is slightly different in that you need to add an @ before the file location, after the field name:
curl -X POST -F 'image=@/path/to/pictures/picture.jpg' http://domain.tld/upload
Using PHP to explore the $_FILES variable array would show file data as though it was uploaded via a form in browser:
Array(
  "image": array(
    "name" => "picture.jpg"
    "type" => "image/jpeg",
    "tmp_name" => "/path/on/server/to/tmp/phprj5rkG",
    "error" => 0,
    "size" => 174476
  )
)
https://davidwalsh.name/curl-post-file

jueves, 20 de julio de 2017

audio player

url  player.php?name=/var/spool/asterisk/voicemail/default/102/INBOX/msg0002.wav

<?php

/*  was needed to make symbolic link from the original path  to a folder called messages
ln -s /var/spool/asterisk/voicemail/default/ messages */

$audio=$_GET['name'];
$newpath=str_replace ("/var/spool/asterisk/voicemail/default/" ,"./messages/",$audio);


//new path would be   ./messages/102/INBOX/msg0002.wav allowing to play

echo <<<"AUDIO"
<audio controls>

  <source src="$newpath" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
AUDIO;

?>

sábado, 8 de julio de 2017

Using with Composer

enabled frist curl
sudo apt-get install php-curl
Or if you're using the old PHP5
sudo apt-get install php5-curl
The recommended method for installing the SDK is via Composer. You can add the PHP SDK to your composer.jsonfile with the require command.
composer require twilio/sdk
If you are using a framework like Laravel, the Twilio SDK may be automatically loaded for you and ready to use in your application. If you're using Composer in an environment that doesn't handle autoloading, you can require the autoload file from the "vendor" directory created by Composer if you used the install command above. Here is a basic example of using the SDK to send a text message.
<?php
// Required if your environment does not handle autoloading
require __DIR__ . '/vendor/autoload.php';

// Use the REST API Client to make requests to the Twilio REST API
use Twilio\Rest\Client;

// Your Account SID and Auth Token from twilio.com/console
$sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$token = 'your_auth_token';
$client = new Client($sid, $token);

// Use the client to do fun stuff like send text messages!
$client->messages->create(
    // the number you'd like to send the message to
    '+15558675309',
    array(
        // A Twilio phone number you purchased at twilio.com/console
        'from' => '+15017250604',
        // the body of the text message you'd like to send
        'body' => 'Hey Jenny! Good luck on the bar exam!'
    )
);
?>

What is PHP Composer?

POSTED BY  ON JANUARY 7TH, 2013
What is PHP Composer
If you have ever written anything in PHP before, you have probably found that it feels like you have to keep re-inventing the wheel anytime you want to do a common task such as User Authentication, Database Management or Request Routing. PHP now has a handful of mature frameworks that have already solved all of these problems, so wouldn’t it be easier to cherry pick the bits that you needed from each framework?