PageRenderTime 28ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/Server/SWXPHP/2.00/flickr/upload/index.php

http://swx-format.googlecode.com/
PHP | 151 lines | 80 code | 26 blank | 45 comment | 9 complexity | 24e30cb4a05487d8954bb81b1072958f MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php
  2. ////////////////////////////////////////////////////////////////////////////////
  3. //
  4. // swxformat.org Flickr Upload script by Aral Balkan.
  5. // Copyright (c) 2007 Aral Balkan. Released under the MIT license.
  6. //
  7. // Used with the SWX Flickr API for initiating photo uploads to Flickr.
  8. // This is outside the SWX Flickr API as it requires binary uploads to Flickr.
  9. //
  10. // You cannot upload photos to Flickr directly from Flash as the FileReference
  11. // call is not compatible with Flickr's API signing. (You will get an
  12. // "Invalid signature" error.) Use this script instead to upload your photos.
  13. //
  14. // Hit this script with a POST request from FileReference in Flash.
  15. //
  16. ////////////////////////////////////////////////////////////////////////////////
  17. // Define E_STRICT if not defined so we don't get errors on PHP 4
  18. if (!defined('E_STRICT')) define('E_STRICT', 2048);
  19. // Error handling
  20. function errorHandler($errorNum, $errorStr, $errorFile, $errorLine)
  21. {
  22. $errorMsg = "Error $errorNum: $errorStr in $errorFile, line $errorLine.";
  23. $GLOBALS['swxLastErrorMessage'] = $errorMsg;
  24. // Display the error message in the PHP error log
  25. error_log($errorMsg);
  26. $errorObj = array('error' => TRUE, 'code' => $errorNum, 'message' => $errorMsg);
  27. //if ($errorNum == E_ERROR || $errorNum == E_WARNING || $errorNum = E_USER_ERROR)
  28. // Error num check replaced by code from http://drupal.org/node/11772#comment-18383.
  29. // This stops PHP5 strict errors from failing a call (e.g., deprecated calls, etc.)
  30. //if (($errorNum & (E_ALL & E_STRICT) ^ (E_NOTICE & E_STRICT)) || $errorNum = E_USER_ERROR)
  31. if ($errorNum != E_STRICT)
  32. {
  33. // On errors and warnings, stop execution and return the
  34. // error message to the client. This is a far better
  35. // alternative to failing silently.
  36. returnError($errorObj);
  37. }
  38. }
  39. /**
  40. * Returns an error message.
  41. *
  42. * @param (str) The error message to return to the client.
  43. *
  44. * @return void (exits)
  45. * @author Aral Balkan
  46. **/
  47. function returnError($errorObj)
  48. {
  49. global $swfCompiler, $debug;
  50. if (strpos($errorObj['message'], 'File to upload is missing.') != false)
  51. {
  52. echo ("Please hit this URL with a FileReference upload() request from Flash.");
  53. }
  54. else
  55. {
  56. echo ($errorObj['message']);
  57. }
  58. error_log($errorObj['message']);
  59. exit();
  60. }
  61. /**
  62. * Returns a result message
  63. *
  64. * @param string $result
  65. * @author Aral Balkan
  66. */
  67. function returnResult($result)
  68. {
  69. global $api;
  70. if ($result === false)
  71. {
  72. // Send the meaningful error message returned by Flickr, instead of false.
  73. echo ('Flickr error '.$api->error_code.': '.$api->error_msg);
  74. }
  75. else
  76. {
  77. echo $result;
  78. }
  79. exit();
  80. }
  81. // Error handling (unfortunately has to be global to support PHP 4)
  82. set_error_handler('errorHandler');
  83. // Turn on error reporting
  84. error_reporting(E_ALL);
  85. // Use the phpFlickr library.
  86. include('../../php/lib/phpFlickr/phpFlickr.php');
  87. $API_KEY = "e7efb59164979981686e62d8bcc473be";
  88. $SHARED_SECRET = "2be064bed40b0b78";
  89. $api = new phpFlickr($API_KEY, $SHARED_SECRET);
  90. if (isset($_FILES['photo']))
  91. {
  92. $photo = $_FILES['photo']['tmp_name'];
  93. }
  94. else
  95. {
  96. trigger_error('File to upload is missing.', E_USER_ERROR);
  97. }
  98. if (isset($_POST['token']))
  99. {
  100. $api->setToken($_POST['token']);
  101. }
  102. else
  103. {
  104. trigger_error('No auth token passed. Uploads require a valid token with write authorization.');
  105. }
  106. $title = isset($_POST['title']) ? $_POST['title'] : NULL;
  107. $description = isset($_POST['description']) ? $_POST['description'] : NULL;
  108. $tags = isset($_POST['tags']) ? $_POST['tags'] : NULL;
  109. $isPublic = isset($_POST['isPublic']) ? $_POST['isPublic'] : NULL;
  110. $isFriend = isset($_POST['isFriend']) ? $_POST['isFriend'] : NULL;
  111. $isFamily = isset($_POST['isFamily']) ? $_POST['isFamily'] : NULL;
  112. $async = isset($_POST['async']);
  113. $result = '';
  114. if ($async)
  115. {
  116. // Do an asynchronous upload.
  117. $result = $api->async_upload ($photo, $title, $description, $tags, $isPublic, $isFriend, $isFamily);
  118. }
  119. else
  120. {
  121. // Do a synchronous upload.
  122. $result = $api->sync_upload ($photo, $title, $description, $tags, $isPublic, $isFriend, $isFamily);
  123. }
  124. returnResult($result);
  125. ?>