TYPO3  7.6
upload-rapidshare.php
Go to the documentation of this file.
1 <?php
9 require_once 'HTTP/Request2.php';
10 
11 // You'll probably want to change this
12 $filename = '/etc/passwd';
13 
14 try {
15  // First step: get an available upload server
16  $request = new HTTP_Request2(
17  'http://rapidshare.com/cgi-bin/rsapi.cgi?sub=nextuploadserver_v1'
18  );
19  $server = $request->send()->getBody();
20  if (!preg_match('/^(\\d+)$/', $server)) {
21  throw new Exception("Invalid upload server: {$server}");
22  }
23 
24  // Calculate file hash, we'll use it later to check upload
25  if (false === ($hash = @md5_file($filename))) {
26  throw new Exception("Cannot calculate MD5 hash of '{$filename}'");
27  }
28 
29  // Second step: upload a file to the available server
31  "http://rs{$server}l3.rapidshare.com/cgi-bin/upload.cgi",
33  );
34  // Adding the file
35  $uploader->addUpload('filecontent', $filename);
36  // This will tell server to return program-friendly output
37  $uploader->addPostParameter('rsapi_v1', '1');
38 
39  $response = $uploader->send()->getBody();
40  if (!preg_match_all('/^(File[^=]+)=(.+)$/m', $response, $m, PREG_SET_ORDER)) {
41  throw new Exception("Invalid response: {$response}");
42  }
43  $rspAry = array();
44  foreach ($m as $item) {
45  $rspAry[$item[1]] = $item[2];
46  }
47  // Check that uploaded file has the same hash
48  if (empty($rspAry['File1.4'])) {
49  throw new Exception("MD5 hash data not found in response");
50  } elseif ($hash != strtolower($rspAry['File1.4'])) {
51  throw new Exception("Upload failed, local MD5 is {$hash}, uploaded MD5 is {$rspAry['File1.4']}");
52  }
53  echo "Upload succeeded\nDownload link: {$rspAry['File1.1']}\nDelete link: {$rspAry['File1.2']}\n";
54 
55 } catch (Exception $e) {
56  echo "Error: " . $e->getMessage();
57 }
58 ?>