/samples/recordingdemo.php

http://github.com/mheadd/tropo-webapi-php · PHP · 38 lines · 28 code · 4 blank · 6 comment · 6 complexity · 1150520e08e995fe9ea2a2a58edc6bb9 MD5 · raw file

  1. <?php
  2. require_once 'tropo.class.php';
  3. // KLogger is a logging class from
  4. // http://codefury.net/projects/klogger/
  5. require_once 'KLogger.php';
  6. $log = new KLogger ( "log.txt" , KLogger::INFO );
  7. // Does the ?record query string exist? If not, this is an incoming call.
  8. if (!array_key_exists('record', $_GET)) {
  9. $tropo = new Tropo();
  10. $tropo->record(array(
  11. 'say' => 'Leave your message at the beep.',
  12. 'url' => getself() . '?record', // append ?record to the URL
  13. ));
  14. print $tropo;
  15. } else {
  16. // Change this path to match the location on your server where you want
  17. // the file to be saved.
  18. $target_path = 'path/to/recording/' . $_FILES['filename']['name'];
  19. if(move_uploaded_file($_FILES['filename']['tmp_name'], $target_path)) {
  20. $log->LogInfo("$target_path [{$_FILES['filename']['size']} bytes] was saved");
  21. } else {
  22. $log->LogError("$target_path could not be saved.");
  23. }
  24. }
  25. // Simple function to get the full URL of the current script.
  26. function getself() {
  27. $pageURL = 'http';
  28. $url = ($_SERVER["HTTPS"] == "on") ? 'https' : 'http';
  29. $url .= "://" . $_SERVER["SERVER_NAME"];
  30. $url .= ($_SERVER["SERVER_PORT"] != "80") ? ':'. $_SERVER["SERVER_PORT"] : '';
  31. $url .= $_SERVER["REQUEST_URI"];
  32. return $url;
  33. }
  34. ?>