Bubelbub

Abload.de - PHP - CURL - Image Upload

Apr 12th, 2013
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.84 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * @author Bubelbub <[email protected]>
  5.  * @version 1.0.0
  6.  *
  7.  * If you would use galleries or save your images into your account: log in
  8.  * -> http://pastebin.com/GJg3rgVm
  9.  */
  10.  
  11. // define the array for images to upload
  12. $imagesToAbload = array(
  13.     'Koala.jpg', // example windows koala image in the same directory
  14.     'C:/Users/Public/Pictures/Sample Pictures/Chrysanthemum.jpg' // example windows chrysanthemum image
  15. );
  16.  
  17. // define the rest of post - for example a gallery id or resize
  18. $post = array(
  19.     'resize'     => 'none', // example: 800x600, 1080, none
  20.     'gallery'    => 'null' // example: 11334, 12398, null
  21. );
  22.  
  23. // convert images to curl format
  24. for ($x = 0; $x < count($imagesToAbload); $x++)
  25. {
  26.     $post['img' . $x] = substr($imagesToAbload[$x], 0, 1) == '@' ? $imagesToAbload[$x] : '@' . $imagesToAbload[$x];
  27. }
  28.  
  29. $ch          = curl_init(); // initialize curl
  30. curl_setopt($ch, CURLOPT_HEADER, 0);
  31. curl_setopt($ch, CURLOPT_VERBOSE, 0);
  32. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  33. curl_setopt($ch, CURLOPT_URL, 'http://www.abload.de/upload.php');
  34. curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); // use cookies for login (not needed)
  35. curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt'); // use cookies for login (not needed)
  36. curl_setopt($ch, CURLOPT_POST, true);
  37. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  38. curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  39. $response    = curl_exec($ch);
  40.  
  41. $key = '';
  42.  
  43. /* @var $dom DOMDocument */
  44. $dom = new DOMDocument;
  45. $dom->loadHTML($response);
  46. foreach ($dom->getElementsByTagName('input') as $elem)
  47. {
  48.     /* @var $elem DOMElement */
  49.     if ($elem->hasAttribute('name') && $elem->hasAttribute('value'))
  50.     {
  51.         if (preg_match('#^key$#i', $elem->getAttribute('name')))
  52.         {
  53.             $key = $elem->getAttribute('value');
  54.         }
  55.     }
  56. }
  57. unset($dom);
  58.  
  59. $ch          = curl_init();
  60. curl_setopt($ch, CURLOPT_HEADER, 0);
  61. curl_setopt($ch, CURLOPT_VERBOSE, 0);
  62. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  63. curl_setopt($ch, CURLOPT_URL, 'http://www.abload.de/uploadComplete.php?key=' . urlencode($key));
  64. curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); // use cookies for login (not needed)
  65. curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt'); // use cookies for login (not needed)
  66. curl_setopt($ch, CURLOPT_POST, false);
  67. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  68. $response    = curl_exec($ch);
  69.  
  70. $images = array();
  71.  
  72. /* @var $dom DOMDocument */
  73. $dom = new DOMDocument;
  74. $dom->loadHTML($response);
  75. foreach ($dom->getElementsByTagName('table') as $elem)
  76. {
  77.     /* @var $elem DOMElement */
  78.     if ($elem->hasAttribute('class'))
  79.     {
  80.         if (preg_match('#^image_links$#i', $elem->getAttribute('class')))
  81.         {
  82.             $images[] = $elem->getAttribute('id');
  83.         }
  84.     }
  85. }
  86.  
  87. $links = '';
  88. foreach ($images as $image)
  89. {
  90.     $tmp     = explode('_', $image);
  91.     $links[] = 'http://www.abload.de/image.php?img=' . $tmp[1] . '.' . $tmp[2];
  92. }
  93.  
  94. var_dump($links);
Advertisement
Add Comment
Please, Sign In to add comment