Advertisement
fileload

fileload curl upload - complete

Jun 21st, 2016
571
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.33 KB | None | 0 0
  1. <?php
  2. /**
  3.  * First: Login and prepare upload
  4.  */
  5. $login = array(
  6.     // Mandatory
  7.     'email' => '[email protected]',
  8.     'password' => md5('secretpasswort'),
  9.  
  10.     // Optional parameters:
  11.     'presentation'  => '', // "1 = ONLY ZIP Download | 2 standard downloadside | 3 Image slider"
  12.     'receiver'      => '', // "[email protected], [email protected]..."
  13.     'message'       => '', // "Here your files."
  14.     'zip_code'      => '', // "0000, 1111"
  15.     'sms_number'    => '', // "+97100000, +97111111"
  16.     'file_password' => '', // "secret password"
  17.     'password_hint' => '', // "password notice / tip"
  18.     'email_alias'   => '' // "[email protected]"
  19. );
  20.  
  21.  
  22. // Do Curl Request
  23. $ch = curl_init();
  24. curl_setopt($ch, CURLOPT_URL, 'https://api.fileload.io/startupload');
  25. curl_setopt($ch, CURLOPT_POST, true);
  26. curl_setopt($ch, CURLOPT_POSTFIELDS, $login);
  27. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  28. $query = curl_exec($ch);
  29. if (curl_errno($ch)) { die('Error: ' . curl_error($ch)); }
  30. curl_close($ch);
  31. $response = json_decode($query)[0];
  32.  
  33. if (isset($response->error) AND $response->error == 'unknown_user') {
  34.     echo 'Error while login. Email or password wrong!';
  35. }
  36.  
  37. echo '<pre>';
  38. print_r($response);
  39. echo '</pre>';
  40.  
  41.  
  42. /**
  43.  * Second: Begin upload...
  44.  */
  45. // Do Curl Upload
  46. $ch = curl_init($response->server);
  47.  
  48. // Create a CURLFile object; Syntax: public CURLFile::__construct ( string $filename [, string $mimetype [, string $postname ]] )
  49. $cfile = new CURLFile('50M.zip','application/zip','50M.zip');
  50.  
  51. // Assign POST data
  52. $prepare_transfer = array(
  53.     'server'      => $response->server,
  54.     'email'       => $response->email,
  55.     'password'    => $response->password,
  56.     'transfer_id' => $response->transfer_id, // OR FIX to upload into same folder ''
  57.     'file'        => $cfile,
  58.     'chunk'       => 0, // Current chunk
  59.     'chunks'      => 0 // Total number of chunks
  60. );
  61.  
  62. // Request a HTTP POST
  63. curl_setopt($ch, CURLOPT_POST, true);
  64.  
  65. // Specify data to POST to server
  66. curl_setopt($ch, CURLOPT_POSTFIELDS, $prepare_transfer);
  67. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  68.  
  69. // Execute the handle
  70. $upload = curl_exec($ch);
  71.  
  72. if (curl_errno($ch)) { die('Error: ' . curl_error($ch)); }
  73. curl_close($ch);
  74.  
  75. $file = json_decode($upload)[0];
  76. #echo $file->url;
  77.  
  78. echo '<pre>';
  79. print_r($file);
  80. echo '</pre>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement