@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -class Xcloner_File_Transfer extends Xcloner_File_System{ |
|
| 3 | +class Xcloner_File_Transfer extends Xcloner_File_System { |
|
| 4 | 4 | |
| 5 | 5 | private $target_url; |
| 6 | 6 | private $transfer_limit = 1048576; //bytes 1MB= 1048576 300KB = 358400 |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | public function set_target($target_url) |
| 10 | 10 | { |
| 11 | - return $this->target_url= $target_url; |
|
| 11 | + return $this->target_url = $target_url; |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | public function get_target() |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | public function transfer_file($file, $start = 0, $hash = "") |
| 21 | 21 | { |
| 22 | - if(!$this->target_url) |
|
| 22 | + if (!$this->target_url) |
|
| 23 | 23 | throw new Exception("Please setup a target url for upload"); |
| 24 | 24 | |
| 25 | 25 | |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | fseek($fp, $start, SEEK_SET); |
| 29 | 29 | |
| 30 | - $binary_data = fread($fp, $this->transfer_limit); |
|
| 30 | + $binary_data = fread($fp, $this->transfer_limit); |
|
| 31 | 31 | |
| 32 | 32 | $tmp_filename = "xcloner_upload_".substr(md5(time()), 0, 5); |
| 33 | 33 | |
@@ -38,11 +38,11 @@ discard block |
||
| 38 | 38 | $send_array = array(); |
| 39 | 39 | |
| 40 | 40 | $send_array['file'] = $file; |
| 41 | - $send_array['start'] = $start; |
|
| 42 | - $send_array['action'] = "write_file"; |
|
| 41 | + $send_array['start'] = $start; |
|
| 42 | + $send_array['action'] = "write_file"; |
|
| 43 | 43 | $send_array['hash'] = $hash; |
| 44 | 44 | #$send_array['blob'] = $binary_data; |
| 45 | - $send_array['blob'] = $this->curl_file_create($tmp_file_path,'application/x-binary',$tmp_filename); |
|
| 45 | + $send_array['blob'] = $this->curl_file_create($tmp_file_path, 'application/x-binary', $tmp_filename); |
|
| 46 | 46 | |
| 47 | 47 | //$data = http_build_query($send_array); |
| 48 | 48 | |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | |
| 52 | 52 | $ch = curl_init(); |
| 53 | - curl_setopt($ch, CURLOPT_URL,$this->target_url); |
|
| 53 | + curl_setopt($ch, CURLOPT_URL, $this->target_url); |
|
| 54 | 54 | |
| 55 | 55 | curl_setopt($ch, CURLOPT_POST, 1); |
| 56 | 56 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
@@ -59,24 +59,24 @@ discard block |
||
| 59 | 59 | curl_setopt($ch, CURLOPT_TIMEOUT, 1200); |
| 60 | 60 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
| 61 | 61 | |
| 62 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $send_array ); |
|
| 62 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $send_array); |
|
| 63 | 63 | curl_setopt($ch, CURLOPT_VERBOSE, true); |
| 64 | 64 | |
| 65 | - $original_result = curl_exec ($ch); |
|
| 65 | + $original_result = curl_exec($ch); |
|
| 66 | 66 | |
| 67 | 67 | $this->get_tmp_filesystem()->delete($tmp_filename); |
| 68 | 68 | |
| 69 | 69 | $result = json_decode($original_result); |
| 70 | 70 | |
| 71 | - if(!$result) |
|
| 72 | - throw new Exception("We have received no valid response from the remote host, original message: ". $original_result); |
|
| 71 | + if (!$result) |
|
| 72 | + throw new Exception("We have received no valid response from the remote host, original message: ".$original_result); |
|
| 73 | 73 | |
| 74 | - if($result->status != 200) |
|
| 74 | + if ($result->status != 200) |
|
| 75 | 75 | { |
| 76 | 76 | throw new Exception($result->response); |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - if(ftell($fp) >= $this->get_storage_filesystem()->getSize($file)) |
|
| 79 | + if (ftell($fp) >= $this->get_storage_filesystem()->getSize($file)) |
|
| 80 | 80 | { |
| 81 | 81 | $this->get_logger()->info(sprintf("Upload done for file %s to target url %s, transferred a total of %s bytes", $file, $this->target_url, ftell($fp))); |
| 82 | 82 | $this->remove_tmp_filesystem(); |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | . ($postname ?: basename($filename)) |
| 94 | 94 | . ($mimetype ? ";type=$mimetype" : ''); |
| 95 | 95 | |
| 96 | - }else{ |
|
| 96 | + } else { |
|
| 97 | 97 | |
| 98 | 98 | return curl_file_create($filename, $mimetype, $postname); |
| 99 | 99 | |