New Paste

 

Recent Pastes

Administrate




iPocalypse Pastebin

PasteID: 2xze8
Pasted by Anonymous, 2011-05-21 10:07:11 GMT
Expires Never
Paste size 3.39 Kb
Toggle Expand   Wrap   Raw
Copy Contents   Copy URL
 
  1. <?php
  2.  
  3. /* PHP API-Adaptor for Knoxious Open Pastebin.
  4.  * ===================================================================================
  5.  * "THE BEER-&-COFFEE-WARE LICENSE" [ Revision 0 ]:
  6.  * - Variation of the "BEER-WARE LICENSE" Rev 42.
  7.  * <xan.manning@gmail.com> wrote this file. As long as you retain this notice you
  8.  * can do whatever you want with this stuff. If we meet some day, and you think
  9.  * this stuff is worth it, you can buy me a beer or coffee in return. Xan Manning
  10.  * ===================================================================================
  11.  */
  12.  
  13. $api = "http://pzt.me/api";
  14.  
  15. /*Source: http://netevil.org/blog/2006/nov/http-post-from-php-without-curl*/
  16. function do_post_request($url, $postdata, $files = NULL) 
  17. 	{ 
  18. 		$data = ""; 
  19. 		$boundary = "---------------------" . substr(md5(rand(0, 32000)), 0, 10); 
  20.  
  21. 		if(is_array($postdata))
  22. 			{ 
  23. 				foreach($postdata as $key => $val) 
  24. 					{ 
  25. 						$data .= "--" . $boundary . "\n"; 
  26. 						$data .= "Content-Disposition: form-data; name=" . $key . "\n\n" . $val . "\n"; 
  27. 					} 
  28. 			}
  29.  
  30. 		$data .= "--" . $boundary . "\n";
  31.  
  32. 		if(is_array($files))
  33. 			{
  34.  
  35. 				foreach($files as $key => $file) 
  36. 					{ 
  37. 						$fileContents = file_get_contents($file['tmp_name']);
  38.  
  39. 						$fileInfo = pathinfo($file['name']);
  40.  
  41. 						switch(strtolower($fileInfo['extension']))
  42. 							{
  43. 								case "jpg":
  44. 									$contentType = "image/jpeg";
  45. 								break;
  46. 								case "jpeg":
  47. 									$contentType = "image/jpeg";
  48. 								break;
  49. 								case "png":
  50. 									$contentType = "image/png";
  51. 								break;
  52. 								case "gif":
  53. 									$contentType = "image/gif";
  54. 								break;
  55. 								default:
  56. 									$contentType = "image/jpeg";
  57. 								break;
  58. 							}
  59.  
  60. 						$data .= "Content-Disposition: form-data; name=" . $key . "; filename=" . $file['name'] . "\n"; 
  61. 						$data .= "Content-Type: " . $contentType . "\n"; 
  62. 						$data .= "Content-Transfer-Encoding: binary\n\n"; 
  63. 						$data .= $fileContents . "\n"; 
  64. 						$data .= "--" . $boundary . "--\n"; 
  65. 					}
  66. 			}
  67.  
  68. 		$params = array('http' => array( 
  69. 				'method' => 'POST', 
  70. 				'header' => 'Content-Type: multipart/form-data; boundary=' . $boundary, 
  71. 				'content' => $data 
  72. 		)); 
  73.  
  74. 		$ctx = stream_context_create($params); 
  75. 		$fp = @fopen($url, 'rb', false, $ctx); 
  76.  
  77. 		if (!$fp)
  78. 			throw new Exception("Problem with " . $url . ", " . $php_errormsg); 
  79.  
  80. 		$response = @stream_get_contents($fp); 
  81.  
  82. 		if ($response === false)
  83. 			throw new Exception("Problem reading data from " . $url . ", " . $php_errormsg); 
  84.  
  85. 		return $response; 
  86. 	} 
  87.  
  88. foreach($_GET as $key => $value)
  89. 	$_GET[$key] = stripslashes($value);
  90.  
  91. foreach($_POST as $key => $value)
  92. 	$_POST[$key] = stripslashes($value);
  93.  
  94. if(count($_POST))
  95. 	$_GET = $_POST;
  96.  
  97. if(@$_GET['callback'] || @$_POST['callback'])
  98. 	$callback = array('left' => $_GET['callback'] . "(", 'right' => ")");
  99.  
  100. if(@$_GET['jsoncallback'] || @$_POST['jsoncallback'])
  101. 	$callback = array('left' => $_GET['jsoncallback'] . "(", 'right' => ")");
  102.  
  103. if(@$_GET['hashtag'] || @$_POST['hashtag'])
  104. 	$api = $api . "@" . $_GET['hashtag'];
  105.  
  106. if(count($_GET) > 0)
  107. 	{
  108. 		foreach($_GET as $key => $val)
  109. 			$get[$key] = $val;
  110. 	}
  111.  
  112.  
  113. if(count($_FILES) > 0)
  114. 	{
  115. 		foreach($_FILES as $key => $val)
  116. 			$files[$key] = $val;
  117. 	}
  118.  
  119. print_r($callback['left'] . do_post_request($api, $get, $files) . $callback['right']);
  120. ?>
  121.  
 
 
 

 
 
 
 
 
Written by Xan Manning, 2010.
YOU NEED FLASH!