├── README.md └── bunnycdn.php /README.md: -------------------------------------------------------------------------------- 1 | # BunnyCDN 2 | BunnyCDN is one of the fastest and most cost effective CDN. 3 | 4 | With this BunnyCDN PHP Class you can easily implement it and turbo charge your website content to deliver it at lighting speed to your visitors. 5 | 6 | For Documentation: [http://codewithmark.com/bunnycdn](http://codewithmark.com/bunnycdn) 7 | 8 | 9 | Code License Agreement : You have the rights to do whatever you like with this library in your projects 10 | 11 | 12 | -------------------------------------------------------------------------------- /bunnycdn.php: -------------------------------------------------------------------------------- 1 | "https://bunnycdn.com/api", 11 | 'storage' => 'https://storage.bunnycdn.com' 12 | ); 13 | 14 | 15 | //--->account > start 16 | 17 | public function Account($api_key_account='') 18 | { 19 | if(!$api_key_account) 20 | { 21 | return array('status' =>'error' ,'code' =>'missing_api_key_account' ,'msg'=> 'missing api key account'); 22 | die(); 23 | } 24 | $this->api_key_account = $api_key_account; 25 | return $this; 26 | } 27 | 28 | public function GetZoneList() 29 | { 30 | /* 31 | will get all of the zones for the account 32 | */ 33 | 34 | if( !$this->api_key_account) 35 | { 36 | return array('status' =>'error' ,'code' =>'api_key_account' ,'msg'=> 'missing acount api key'); 37 | die(); 38 | } 39 | 40 | $key = $this->api_key_account; 41 | $api_url = $this->api_url['zone'].'/pullzone'; 42 | 43 | $get_header = $this->create_header($key); 44 | 45 | $api_call = $this->run( array('call_method' => 'GET', 'api_url' => $api_url,'header' => $get_header , ) ); 46 | 47 | if($api_call['http_code'] !=200) 48 | { 49 | //error message 50 | $request_array = json_decode(json_encode($api_call['data'])); 51 | $result = array 52 | ( 53 | "status" => 'error', 54 | "http_code"=>$api_call['http_code'], 55 | "msg" => json_decode($request_array)->Message , 56 | ); 57 | return $result; 58 | die(); 59 | } 60 | 61 | $zone_data = json_decode($api_call['data']); 62 | 63 | $a1 = array(); 64 | 65 | foreach ($zone_data as $k1 => $v1) 66 | { 67 | $arr_hostnames = array(); 68 | 69 | //--->get all the hostnames > start 70 | if($v1->Hostnames) 71 | { 72 | foreach ($v1->Hostnames as $key => $v2) 73 | { 74 | array_push($arr_hostnames, $v2->Value); 75 | } 76 | } 77 | //--->get all the hostnames > end 78 | 79 | $d = array 80 | ( 81 | "zone_id" => $v1->Id, 82 | "zone_name"=>$v1->Name, 83 | "monthly_bandwidth_used" =>$this->format_bytes($v1->MonthlyBandwidthUsed), 84 | "host_names" =>$arr_hostnames, 85 | ); 86 | array_push($a1,$d); 87 | } 88 | 89 | return array('status' => 'success', 'zone_smry'=>$a1,"zone_details" => $zone_data); 90 | 91 | } 92 | public function GetZone($zone_id = '') 93 | { 94 | /* 95 | will get a user zone for the account 96 | */ 97 | if( !$this->api_key_account) 98 | { 99 | return array('status' =>'error' ,'code' =>'api_key_account' ,'msg'=> 'missing acount api key'); 100 | die(); 101 | } 102 | 103 | if(!$zone_id) 104 | { 105 | return array('status' =>'error' ,'code' =>'zone_id' ,'msg'=> 'missing zone id'); 106 | die(); 107 | } 108 | 109 | 110 | $key = $this->api_key_account; 111 | $api_url = $this->api_url['zone'].'/pullzone/'.$zone_id; 112 | 113 | $get_header = $this->create_header($key); 114 | $post_data_array = array('id'=>$zone_id); 115 | 116 | $api_call = $this->run( array('call_method' => 'GET', 'api_url' => $api_url,'header' => $get_header , 'post_data_array'=>$post_data_array) ); 117 | 118 | 119 | if($api_call['http_code'] !=200) 120 | { 121 | //error message 122 | $request_array = json_decode(json_encode($api_call['data'])); 123 | $result = array 124 | ( 125 | "status" => 'error', 126 | "http_code"=>$api_call['http_code'], 127 | "msg" => json_decode($request_array) , 128 | ); 129 | return $result; 130 | die(); 131 | } 132 | 133 | $zone_data = json_decode($api_call['data']); 134 | 135 | $a1 = array(); 136 | $arr_hostnames = array(); 137 | 138 | //--->get all the hostnames > start 139 | if($zone_data->Hostnames) 140 | { 141 | foreach ($zone_data->Hostnames as $key => $v1) 142 | { 143 | array_push($arr_hostnames, $v1->Value); 144 | } 145 | } 146 | //--->get all the hostnames > end 147 | 148 | $d = array 149 | ( 150 | "zone_id" => $zone_data->Id, 151 | "zone_name"=>$zone_data->Name, 152 | "monthly_bandwidth_used" =>$this->format_bytes($zone_data->MonthlyBandwidthUsed), 153 | "host_names" =>$arr_hostnames, 154 | ); 155 | array_push($a1,$d); 156 | 157 | return array('status' => 'success', 'zone_smry'=>$a1,"zone_details" => $zone_data); 158 | die(); 159 | } 160 | 161 | 162 | public function CreateNewZone($zone_name = '', $zone_url = '') 163 | { 164 | /* 165 | will create a new zone for the account 166 | */ 167 | 168 | if( !$this->api_key_account) 169 | { 170 | return array('status' =>'error' ,'code' =>'api_key_account' ,'msg'=> 'missing acount api key'); 171 | die(); 172 | } 173 | 174 | if(!$zone_name) 175 | { 176 | return array('status' =>'error' ,'code' =>'zone_name' ,'msg'=> 'missing zone name'); 177 | die(); 178 | } 179 | 180 | if(!$zone_url) 181 | { 182 | return array('status' =>'error' ,'code' =>'zone_url' ,'msg'=> 'missing zone url'); 183 | die(); 184 | } 185 | 186 | $key = $this->api_key_account; 187 | $api_url = $this->api_url['zone'].'/pullzone'; 188 | 189 | $get_header = $this->create_header($key); 190 | 191 | 192 | $post_data_array = array('Name' => $zone_name, 'OriginUrl' => $zone_url); 193 | 194 | $api_call = $this->run( array('call_method' => 'POST', 'api_url' => $api_url,'header' => $get_header , 'post_data_array'=>$post_data_array) ); 195 | 196 | if($api_call['http_code'] !=201) 197 | { 198 | //error message 199 | $request_array = json_decode(json_encode($api_call['data'])); 200 | $result = array 201 | ( 202 | "status" => 'error', 203 | "http_code"=>$api_call['http_code'], 204 | "msg" => json_decode($request_array) , 205 | ); 206 | return $result; 207 | die(); 208 | } 209 | 210 | //convert to php array for data parsing 211 | $zone_data = json_decode($api_call['data']); 212 | 213 | //--->get all the hostnames > start 214 | $cdnurl = ''; 215 | if($zone_data->Hostnames) 216 | { 217 | foreach ($zone_data->Hostnames as $key => $v1) 218 | { 219 | $cdnurl = $v1->Value; 220 | } 221 | } 222 | //--->get all the hostnames > end 223 | 224 | 225 | 226 | return array 227 | ( 228 | 'status' => 'success', 229 | "zone_id" => $zone_data->Id, 230 | "zone_name"=>$zone_data->Name, 231 | "origin_url"=>$zone_data->OriginUrl, 232 | "cdn_url"=>$cdnurl, 233 | "zone_details" => $zone_data 234 | ); 235 | die(); 236 | } 237 | 238 | 239 | public function DeleteZone($zone_id= '') 240 | { 241 | /* 242 | will delete a zone for the account 243 | */ 244 | 245 | if( !$this->api_key_account) 246 | { 247 | return array('status' =>'error' ,'code' =>'api_key_account' ,'msg'=> 'missing acount api key'); 248 | die(); 249 | } 250 | 251 | if(!$zone_id) 252 | { 253 | return array('status' =>'error' ,'code' =>'zone_id' ,'msg'=> 'missing zone id'); 254 | die(); 255 | } 256 | 257 | 258 | $key = $this->api_key_account; 259 | $api_url = $this->api_url['zone'].'/pullzone/'. $zone_id; 260 | 261 | $get_header = $this->create_header($key); 262 | 263 | $api_call = $this->run( array('call_method' => 'DELETE', 'api_url' => $api_url,'header' => $get_header , ) ); 264 | 265 | 266 | if($api_call['http_code'] !=200 && $api_call['http_code'] !=302) 267 | { 268 | //error message 269 | $request_array = json_decode(json_encode($api_call['data'])); 270 | $result = array 271 | ( 272 | "status" => 'error', 273 | "http_code"=>$api_call['http_code'], 274 | "msg" => json_decode($request_array) , 275 | ); 276 | return $result; 277 | die(); 278 | } 279 | 280 | return array( 281 | 'status' => 'success', 282 | "msg" => $api_call, 283 | 284 | ); 285 | //return $api_call; 286 | die(); 287 | } 288 | 289 | 290 | 291 | public function PurgeZoneCache($zone_id= '') 292 | { 293 | /* 294 | will purge cache for the whole zone 295 | */ 296 | 297 | if( !$this->api_key_account) 298 | { 299 | return array('status' =>'error' ,'code' =>'api_key_account' ,'msg'=> 'missing acount api key'); 300 | die(); 301 | } 302 | 303 | if(!$zone_id) 304 | { 305 | return array('status' =>'error' ,'code' =>'zone_id' ,'msg'=> 'missing zone id'); 306 | die(); 307 | } 308 | 309 | 310 | $key = $this->api_key_account; 311 | $api_url = $this->api_url['zone'].'/pullzone/'. $zone_id.'/purgeCache'; 312 | 313 | $get_header = $this->create_header($key); 314 | 315 | 316 | $api_call = $this->run( array('call_method' => 'POST', 'api_url' => $api_url,'header' => $get_header , ) ); 317 | 318 | 319 | if($api_call['http_code'] !=200 ) 320 | { 321 | //error message 322 | $request_array = json_decode(json_encode($api_call['data'])); 323 | $result = array 324 | ( 325 | "status" => 'error', 326 | "http_code"=>$api_call['http_code'], 327 | "msg" => json_decode($request_array) , 328 | ); 329 | return $result; 330 | die(); 331 | } 332 | 333 | return array( 334 | 'status' => 'success', 335 | "msg" => $api_call, 336 | ); 337 | die(); 338 | } 339 | 340 | 341 | public function AddHostName($zone_id = '', $host_name_url = '') 342 | { 343 | /* 344 | will add a host name for the zone 345 | */ 346 | 347 | if( !$this->api_key_account) 348 | { 349 | return array('status' =>'error' ,'code' =>'api_key_account' ,'msg'=> 'missing acount api key'); 350 | die(); 351 | } 352 | 353 | if(!$zone_id) 354 | { 355 | return array('status' =>'error' ,'code' =>'zone_id' ,'msg'=> 'missing zone id'); 356 | die(); 357 | } 358 | 359 | if(!$host_name_url) 360 | { 361 | return array('status' =>'error' ,'code' =>'host_name_url' ,'msg'=> 'missing host name url'); 362 | die(); 363 | } 364 | 365 | $key = $this->api_key_account; 366 | $api_url = $this->api_url['zone'].'/pullzone/addHostname'; 367 | 368 | $get_header = $this->create_header($key); 369 | 370 | 371 | $post_data_array = array('PullZoneId' => $zone_id, 'Hostname' => $host_name_url); 372 | 373 | $api_call = $this->run( array('call_method' => 'POST', 'api_url' => $api_url,'header' => $get_header , 'post_data_array'=>$post_data_array) ); 374 | 375 | if($api_call['http_code'] !=200 ) 376 | { 377 | //error message 378 | $request_array = json_decode(json_encode($api_call['data'])); 379 | $result = array 380 | ( 381 | "status" => 'error', 382 | "http_code"=>$api_call['http_code'], 383 | "msg" => json_decode($request_array) , 384 | ); 385 | return $result; 386 | die(); 387 | } 388 | 389 | return array( 390 | 'status' => 'success', 391 | "msg" => $api_call, 392 | ); 393 | die(); 394 | } 395 | 396 | 397 | public function DeleteHostName($zone_id = '', $host_name_url = '') 398 | { 399 | /* 400 | will delete a host name for the zone 401 | */ 402 | 403 | if( !$this->api_key_account) 404 | { 405 | return array('status' =>'error' ,'code' =>'api_key_account' ,'msg'=> 'missing acount api key'); 406 | die(); 407 | } 408 | 409 | if(!$zone_id) 410 | { 411 | return array('status' =>'error' ,'code' =>'zone_id' ,'msg'=> 'missing zone id'); 412 | die(); 413 | } 414 | 415 | if(!$host_name_url) 416 | { 417 | return array('status' =>'error' ,'code' =>'host_name_url' ,'msg'=> 'missing host name url'); 418 | die(); 419 | } 420 | 421 | $key = $this->api_key_account; 422 | $api_url = $this->api_url['zone'].'/pullzone/deleteHostname?id='.$zone_id.'&hostname='.$host_name_url ; 423 | 424 | $get_header = $this->create_header($key); 425 | 426 | 427 | $api_call = $this->run( array('call_method' => 'DELETE', 'api_url' => $api_url,'header' => $get_header , ) ); 428 | 429 | if($api_call['http_code'] !=200 ) 430 | { 431 | //error message 432 | $request_array = json_decode(json_encode($api_call['data'])); 433 | $result = array 434 | ( 435 | "status" => 'error', 436 | "http_code"=>$api_call['http_code'], 437 | "msg" => json_decode($request_array) , 438 | ); 439 | return $result; 440 | die(); 441 | } 442 | 443 | return array( 444 | 'status' => 'success', 445 | "msg" => $api_call, 446 | ); 447 | die(); 448 | } 449 | 450 | public function AddBlockedIP($zone_id = '', $blocked_ip = '') 451 | { 452 | /* 453 | will add a blocked ip for the zone 454 | */ 455 | 456 | if( !$this->api_key_account) 457 | { 458 | return array('status' =>'error' ,'code' =>'api_key_account' ,'msg'=> 'missing acount api key'); 459 | die(); 460 | } 461 | 462 | if(!$zone_id) 463 | { 464 | return array('status' =>'error' ,'code' =>'zone_id' ,'msg'=> 'missing zone id'); 465 | die(); 466 | } 467 | 468 | if(!$blocked_ip) 469 | { 470 | return array('status' =>'error' ,'code' =>'blocked_ip' ,'msg'=> 'missing blocked ip'); 471 | die(); 472 | } 473 | 474 | $key = $this->api_key_account; 475 | $api_url = $this->api_url['zone'].'/pullzone/addBlockedIp' ; 476 | 477 | $get_header = $this->create_header($key); 478 | 479 | 480 | $post_data_array = array('PullZoneId' => $zone_id, 'BlockedIp' => $blocked_ip); 481 | 482 | $api_call = $this->run( array('call_method' => 'POST', 'api_url' => $api_url,'header' => $get_header , 'post_data_array'=>$post_data_array) ); 483 | 484 | if($api_call['http_code'] !=200 ) 485 | { 486 | //error message 487 | $request_array = json_decode(json_encode($api_call['data'])); 488 | $result = array 489 | ( 490 | "status" => 'error', 491 | "http_code"=>$api_call['http_code'], 492 | "msg" => json_decode($request_array) , 493 | ); 494 | return $result; 495 | die(); 496 | } 497 | 498 | return array( 499 | 'status' => 'success', 500 | "msg" => $api_call, 501 | ); 502 | die(); 503 | } 504 | 505 | 506 | public function RemoveBlockedIP($zone_id = '', $blocked_ip = '') 507 | { 508 | /* 509 | will remove a blocked ip for the zone 510 | */ 511 | 512 | if( !$this->api_key_account) 513 | { 514 | return array('status' =>'error' ,'code' =>'api_key_account' ,'msg'=> 'missing acount api key'); 515 | die(); 516 | } 517 | 518 | if(!$zone_id) 519 | { 520 | return array('status' =>'error' ,'code' =>'zone_id' ,'msg'=> 'missing zone id'); 521 | die(); 522 | } 523 | 524 | if(!$blocked_ip) 525 | { 526 | return array('status' =>'error' ,'code' =>'blocked_ip' ,'msg'=> 'missing blocked ip'); 527 | die(); 528 | } 529 | 530 | $key = $this->api_key_account; 531 | $api_url = $this->api_url['zone'].'/pullzone/removeBlockedIp' ; 532 | 533 | $get_header = $this->create_header($key); 534 | 535 | 536 | $post_data_array = array('PullZoneId' => $zone_id, 'BlockedIp' => $blocked_ip); 537 | 538 | $api_call = $this->run( array('call_method' => 'POST', 'api_url' => $api_url,'header' => $get_header , 'post_data_array'=>$post_data_array) ); 539 | 540 | if($api_call['http_code'] !=200 ) 541 | { 542 | //error message 543 | $request_array = json_decode(json_encode($api_call['data'])); 544 | $result = array 545 | ( 546 | "status" => 'error', 547 | "http_code"=>$api_call['http_code'], 548 | "msg" => json_decode($request_array) , 549 | ); 550 | return $result; 551 | die(); 552 | } 553 | 554 | return array( 555 | 'status' => 'success', 556 | "msg" => $api_call, 557 | ); 558 | die(); 559 | } 560 | 561 | public function PurgeURL($url = '') 562 | { 563 | /* 564 | will purge a url for the account 565 | */ 566 | 567 | if( !$this->api_key_account) 568 | { 569 | return array('status' =>'error' ,'code' =>'api_key_account' ,'msg'=> 'missing acount api key'); 570 | die(); 571 | } 572 | 573 | if(!$url) 574 | { 575 | return array('status' =>'error' ,'code' =>'url' ,'msg'=> 'missing url'); 576 | die(); 577 | } 578 | 579 | $key = $this->api_key_account; 580 | $api_url = $this->api_url['zone'].'/purge?url='.$url ; 581 | 582 | $get_header = $this->create_header($key); 583 | 584 | 585 | //$post_data_array = array('PullZoneId' => $zone_id, 'BlockedIp' => $blocked_ip); 586 | 587 | $api_call = $this->run( array('call_method' => 'POST', 'api_url' => $api_url,'header' => $get_header , )); 588 | 589 | if($api_call['http_code'] !=200 ) 590 | { 591 | //error message 592 | $request_array = json_decode(json_encode($api_call['data'])); 593 | $result = array 594 | ( 595 | "status" => 'error', 596 | "http_code"=>$api_call['http_code'], 597 | "msg" => json_decode($request_array) , 598 | ); 599 | return $result; 600 | die(); 601 | } 602 | 603 | return array( 604 | 'status' => 'success', 605 | "msg" => $api_call, 606 | ); 607 | die(); 608 | } 609 | 610 | public function Stats() 611 | { 612 | /* 613 | will get all the statistics for the account 614 | */ 615 | 616 | if( !$this->api_key_account) 617 | { 618 | return array('status' =>'error' ,'code' =>'api_key_account' ,'msg'=> 'missing acount api key'); 619 | die(); 620 | } 621 | 622 | $key = $this->api_key_account; 623 | $api_url = $this->api_url['zone'].'/statistics'; 624 | 625 | $get_header = $this->create_header($key); 626 | 627 | $api_call = $this->run( array('call_method' => 'GET', 'api_url' => $api_url,'header' => $get_header , )); 628 | 629 | if($api_call['http_code'] !=200 ) 630 | { 631 | //error message 632 | $request_array = json_decode(json_encode($api_call['data'])); 633 | $result = array 634 | ( 635 | "status" => 'error', 636 | "http_code"=>$api_call['http_code'], 637 | "msg" => json_decode($request_array) , 638 | ); 639 | return $result; 640 | die(); 641 | } 642 | 643 | return array( 644 | 'status' => 'success', 645 | "msg" => json_decode( ($api_call['data'])), 646 | ); 647 | die(); 648 | } 649 | 650 | 651 | 652 | 653 | public function Billing() 654 | { 655 | /* 656 | will get the billing information for the account 657 | */ 658 | 659 | if( !$this->api_key_account) 660 | { 661 | return array('status' =>'error' ,'code' =>'api_key_account' ,'msg'=> 'missing acount api key'); 662 | die(); 663 | } 664 | 665 | $key = $this->api_key_account; 666 | $api_url = $this->api_url['zone'].'/billing'; 667 | 668 | $get_header = $this->create_header($key); 669 | 670 | $api_call = $this->run( array('call_method' => 'GET', 'api_url' => $api_url,'header' => $get_header , )); 671 | 672 | if($api_call['http_code'] !=200 ) 673 | { 674 | //error message 675 | $request_array = json_decode(json_encode($api_call['data'])); 676 | $result = array 677 | ( 678 | "status" => 'error', 679 | "http_code"=>$api_call['http_code'], 680 | "msg" => json_decode($request_array) , 681 | ); 682 | return $result; 683 | die(); 684 | } 685 | 686 | return array( 687 | 'status' => 'success', 688 | "msg" => json_decode( ($api_call['data'])), 689 | ); 690 | die(); 691 | } 692 | 693 | 694 | public function ApplyCode($apply_code = '') 695 | { 696 | /* 697 | will apply a promo code to account to save money 698 | */ 699 | 700 | if( !$this->api_key_account) 701 | { 702 | return array('status' =>'error' ,'code' =>'api_key_account' ,'msg'=> 'missing acount api key'); 703 | die(); 704 | } 705 | 706 | if(!$apply_code) 707 | { 708 | return array('status' =>'error' ,'code' =>'apply_code' ,'msg'=> 'missing apply code'); 709 | die(); 710 | } 711 | 712 | $key = $this->api_key_account; 713 | $api_url = $this->api_url['zone'].'/billing/applycode?couponCode='.$apply_code ; 714 | 715 | $get_header = $this->create_header($key); 716 | 717 | $api_call = $this->run( array('call_method' => 'GET', 'api_url' => $api_url,'header' => $get_header , )); 718 | 719 | if($api_call['http_code'] !=200 ) 720 | { 721 | //error message 722 | $request_array = json_decode(json_encode($api_call['data'])); 723 | $result = array 724 | ( 725 | "status" => 'error', 726 | "http_code"=>$api_call['http_code'], 727 | "msg" => json_decode($request_array) , 728 | ); 729 | return $result; 730 | die(); 731 | } 732 | 733 | return array( 734 | 'status' => 'success', 735 | "msg" => $api_call, 736 | ); 737 | die(); 738 | } 739 | 740 | //--->account > end 741 | 742 | 743 | 744 | 745 | //--->storage > start 746 | 747 | public function Storage($api_key_storage='') 748 | { 749 | if(!$api_key_storage) 750 | { 751 | return array('status' =>'error' ,'code' =>'api_key_storage' ,'msg'=> 'missing storage api key'); 752 | die(); 753 | } 754 | 755 | $this->api_key_storage = $api_key_storage; 756 | return $this; 757 | } 758 | 759 | public function GetStorageZone($storage_path ='') 760 | { 761 | /* 762 | will get all of the files and subfolders for storage zone 763 | */ 764 | 765 | if( !$this->api_key_storage) 766 | { 767 | return array('status' =>'error' ,'code' =>'api_key_storage' ,'msg'=> 'missing storage api key'); 768 | die(); 769 | } 770 | if(!$storage_path ) 771 | { 772 | return array('status' =>'error' ,'code' =>'missing_zone_id' ,'msg'=> 'missing zone id'); 773 | die(); 774 | } 775 | 776 | $key = $this->api_key_storage; 777 | $api_url = $this->fix_url($this->api_url['storage'].$storage_path ); 778 | 779 | $get_header = $this->create_header($key); 780 | 781 | $api_call = $this->run( array('call_method' => 'GET', 'api_url' => $api_url,'header' => $get_header ,) ); 782 | 783 | if($api_call['http_code'] !=200 ) 784 | { 785 | //error message 786 | $request_array = json_decode(json_encode($api_call['data'])); 787 | $result = array 788 | ( 789 | "status" => 'error', 790 | "http_code"=>$api_call['http_code'], 791 | "msg" => json_decode($request_array) , 792 | ); 793 | return $result; 794 | die(); 795 | } 796 | $request_array = json_decode(json_encode($api_call['data'])); 797 | 798 | //convert to php array for data parsing 799 | $zone_data = json_decode(($api_call['data'])); 800 | 801 | //--->get all the hostnames > start 802 | $files = array(); 803 | $folders = array(); 804 | //--->get all the hostnames > start 805 | if($zone_data) 806 | { 807 | foreach ($zone_data as $key => $v1) 808 | { 809 | $folder_path = str_replace('/'.$v1->StorageZoneName.'/',"/",$v1->Path); 810 | if(!$v1->IsDirectory) 811 | { 812 | //files only 813 | $d = array 814 | ( 815 | "storage_zone_name"=>$v1->StorageZoneName, 816 | "folder_path"=>$folder_path, 817 | "file_name" =>$v1->ObjectName, 818 | "file_zone_path" =>$v1->Path.$v1->ObjectName, 819 | "file_dl_path" => $folder_path.$v1->ObjectName, 820 | ); 821 | array_push($files, $d); 822 | } 823 | else if($v1->IsDirectory) 824 | { 825 | //folders only 826 | $d = array 827 | ( 828 | "storage_zone_name"=>$v1->StorageZoneName, 829 | "main_folder"=>$v1->Path, 830 | "sub_folder" =>$v1->ObjectName, 831 | "folder_path" =>$v1->Path.$v1->ObjectName, 832 | ); 833 | array_push($folders, $d); 834 | } 835 | } 836 | } 837 | //--->get all the hostnames > end 838 | 839 | return array( 840 | 'status' => 'success', 841 | 'zone_smry'=> array('folders' => $folders,'files' => $files,), 842 | "zone_details" => json_decode($request_array), 843 | ); 844 | die(); 845 | } 846 | 847 | 848 | 849 | 850 | public function PutFile($local_upload_file_path ='', $storage_zone_path='', $storage_zone_file_path='' ) 851 | { 852 | /* 853 | will upload a file to storage zone 854 | */ 855 | 856 | if( !$this->api_key_storage) 857 | { 858 | return array('status' =>'error' ,'code' =>'api_key_storage' ,'msg'=> 'missing storage api key'); 859 | die(); 860 | } 861 | if(!$local_upload_file_path ) 862 | { 863 | return array('status' =>'error' ,'code' =>'local_upload_file_path' ,'msg'=> 'missing file path'); 864 | die(); 865 | } 866 | 867 | if(!$storage_zone_file_path ) 868 | { 869 | return array('status' =>'error' ,'code' =>'storage_zone_file_path' ,'msg'=> 'missing storage zone file path'); 870 | die(); 871 | } 872 | 873 | 874 | 875 | //file variables 876 | 877 | //make folder and file name seo friendly to ensure no problem happen 878 | $cdn_file_path = $this->seo_file_name($storage_zone_file_path); 879 | 880 | $path_info = pathinfo($cdn_file_path); 881 | 882 | //will get folders path 883 | $info_dir_name = strtolower($path_info['dirname']); 884 | 885 | //will get file name with ext 886 | $info_file_name = $path_info['basename']; 887 | 888 | //$info_file_name = $path_info['filename']; 889 | $info_file_ext = $path_info['extension']; 890 | 891 | 892 | $storage_file_path = $storage_zone_path .$cdn_file_path; 893 | 894 | 895 | 896 | $key = $this->api_key_storage; 897 | $api_url = $this->fix_url($this->api_url['storage'].$storage_file_path); 898 | 899 | $get_header = $this->create_header($key); 900 | 901 | 902 | // Open the file 903 | $file = $local_upload_file_path; 904 | $fileStream = fopen($file, "r") or die("Unable to open file!"); 905 | $dataLength = filesize($file); 906 | 907 | 908 | // Initialize and configure curl 909 | $curl = curl_init(); 910 | curl_setopt_array( $curl, 911 | array( CURLOPT_CUSTOMREQUEST => 'PUT' 912 | , CURLOPT_URL => $api_url 913 | , CURLOPT_RETURNTRANSFER => 1 // means output will be a return value from curl_exec() instead of simply echoed 914 | , CURLOPT_TIMEOUT => 60000 // in case you are uploading a really BIG file!! 915 | , CURLOPT_FOLLOWLOCATION => 0 // don't follow any Location headers, use only the CURLOPT_URL, this is for security 916 | , CURLOPT_FAILONERROR => 0 // do not fail verbosely fi the http_code is an error, this is for security 917 | , CURLOPT_SSL_VERIFYPEER => 1 // do verify the SSL of CURLOPT_URL, this is for security 918 | , CURLOPT_VERBOSE => 0 // don't output verbosely to stderr, this is for security 919 | , CURLOPT_INFILE => $fileStream 920 | , CURLOPT_INFILESIZE => $dataLength 921 | , CURLOPT_UPLOAD => 1 922 | , CURLOPT_HTTPHEADER => array( 923 | 'AccessKey: ' . $key 924 | ) 925 | ) ); 926 | 927 | // Send the request 928 | $response = curl_exec($curl); 929 | $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); 930 | 931 | // Cleanup 932 | curl_close($curl); 933 | fclose($fileStream); 934 | 935 | if($http_code !=201 ) 936 | { 937 | //error message 938 | $request_array = json_decode(json_encode($response)); 939 | $result = array 940 | ( 941 | "status" => 'error', 942 | "http_code"=>$http_code, 943 | "msg" => json_decode($request_array) , 944 | ); 945 | return $result; 946 | die(); 947 | } 948 | 949 | 950 | return array( 951 | 'status' => 'success', 952 | 'file_name' => $info_file_name , 953 | 'storage_file_path' => $storage_file_path, 954 | 'cdn_file_path' => $cdn_file_path, 955 | 'msg'=> $response, 956 | ); 957 | die(); 958 | 959 | } 960 | 961 | public function GetFile($storage_path ='' ) 962 | { 963 | /* 964 | will get a file from the storage zone 965 | */ 966 | 967 | if(!$storage_path || !$this->api_key_storage) 968 | { 969 | return array('status' =>'error' ,'code' =>'missing_api_key_storage' ,'msg'=> 'missing storage missing api'); 970 | die(); 971 | } 972 | 973 | $key = $this->api_key_storage; 974 | $api_url = $this->fix_url($this->api_url['storage'].$storage_path ); 975 | 976 | $accessKey = $this->api_key_storage; 977 | 978 | $get_header = $this->create_header($key); 979 | 980 | $api_call = $this->run( array('call_method' => 'GET', 'api_url' => $api_url,'header' => $get_header ) ); 981 | 982 | if($api_call['http_code'] !=200 ) 983 | { 984 | //error message 985 | $request_array = json_decode(json_encode($api_call['data'])); 986 | $result = array 987 | ( 988 | "status" => 'error', 989 | "http_code"=>$api_call['http_code'], 990 | "msg" => json_decode($request_array) , 991 | ); 992 | return $result; 993 | die(); 994 | } 995 | 996 | $path_info = pathinfo($storage_path); 997 | $file_name = $path_info['basename']; 998 | 999 | 1000 | $file = $api_call['data']; 1001 | 1002 | 1003 | header("Content-type: application/octet-stream"); 1004 | header("Content-Disposition: attachment; filename=$file_name"); 1005 | //will force to download... 1006 | echo $file ; 1007 | 1008 | 1009 | } 1010 | 1011 | 1012 | 1013 | 1014 | public function DeleteFile($storage_path ='') 1015 | { 1016 | /* 1017 | will delete a file from the storage zone 1018 | */ 1019 | 1020 | if(!$storage_path || !$this->api_key_storage) 1021 | { 1022 | return array('status' =>'error' ,'code' =>'missing_api_key_storage' ,'msg'=> 'missing storage missing api'); 1023 | die(); 1024 | } 1025 | 1026 | $key = $this->api_key_storage; 1027 | $api_url = $this->fix_url($this->api_url['storage'].$storage_path ); 1028 | 1029 | $accessKey = $this->api_key_storage; 1030 | 1031 | $get_header = $this->create_header($key); 1032 | 1033 | $api_call = $this->run( array('call_method' => 'DELETE', 'api_url' => $api_url,'header' => $get_header ) ); 1034 | 1035 | if($api_call['http_code'] !=200 ) 1036 | { 1037 | //error message 1038 | $request_array = json_decode(json_encode($api_call['data'])); 1039 | $result = array 1040 | ( 1041 | "status" => 'error', 1042 | "http_code"=>$api_call['http_code'], 1043 | "msg" => json_decode($request_array) , 1044 | ); 1045 | return $result; 1046 | die(); 1047 | } 1048 | 1049 | return array( 1050 | 'status' => 'success', 1051 | 'msg'=> $api_call, 1052 | ); 1053 | die(); 1054 | 1055 | } 1056 | 1057 | public function SecureLink($host_name ='', $security_key ='', $file_path='', $expiry_hr = 24) 1058 | { 1059 | $securityKey = $security_key; 1060 | $path = $file_path; 1061 | 1062 | // Set the time of expiry to one hour from now 1063 | $expires = (time() + 3600 ) * $expiry_hr; 1064 | 1065 | // Generate the token 1066 | $hashableBase = $securityKey.$path.$expires; 1067 | 1068 | // If using IP validation 1069 | // $hashableBase .= "146.14.19.7"; 1070 | 1071 | $token = md5($hashableBase, true); 1072 | $token = base64_encode($token); 1073 | $token = strtr($token, '+/', '-_'); 1074 | $token = str_replace('=', '', $token); 1075 | 1076 | // Generate the URL 1077 | $url = "$host_name$file_path?token={$token}&expires={$expires}" ; 1078 | 1079 | return $url; 1080 | } 1081 | //--->storage > end 1082 | 1083 | public function DownloadFile($file_url = '', $oupt_file_name='') 1084 | { 1085 | //this is a fast way to download a file 1086 | //remove any query string data 1087 | if(isset($oupt_file_name)) 1088 | { 1089 | $file_name = $oupt_file_name; 1090 | } 1091 | if(empty($oupt_file_name)) 1092 | { 1093 | $file_name = preg_replace('/\?.*/', '', basename($file_url)); 1094 | } 1095 | 1096 | header("Content-Type: application/octet-stream"); 1097 | header("Content-Transfer-Encoding: Binary"); 1098 | header("Content-disposition: attachment; filename=$file_name"); 1099 | readfile($file_url); 1100 | } 1101 | 1102 | 1103 | public function DownloadFile1($file_url) 1104 | { 1105 | /* 1106 | this is a slow way to download a file 1107 | will allow you to download a remote file from any server that is accessible 1108 | */ 1109 | 1110 | $filename = $file_url; 1111 | $filedata = @file_get_contents($filename); 1112 | 1113 | // SUCCESS 1114 | if ($filedata) 1115 | { 1116 | // GET A NAME FOR THE FILE 1117 | //remove any query string data 1118 | $basename = preg_replace('/\?.*/', '', basename($file_url)); 1119 | //$basename = basename($filename); 1120 | 1121 | // THESE HEADERS ARE USED ON ALL BROWSERS 1122 | header("Content-Type: application-x/force-download"); 1123 | header("Content-Disposition: attachment; filename=$basename"); 1124 | header("Content-length: " . (string)(strlen($filedata))); 1125 | header("Expires: ".gmdate("D, d M Y H:i:s", mktime(date("H")+2, date("i"), date("s"), date("m"), date("d"), date("Y")))." GMT"); 1126 | header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); 1127 | 1128 | // THIS HEADER MUST BE OMITTED FOR IE 6+ 1129 | if (FALSE === strpos($_SERVER["HTTP_USER_AGENT"], 'MSIE ')) 1130 | { 1131 | header("Cache-Control: no-cache, must-revalidate"); 1132 | } 1133 | 1134 | // THIS IS THE LAST HEADER 1135 | header("Pragma: no-cache"); 1136 | 1137 | // FLUSH THE HEADERS TO THE BROWSER 1138 | flush(); 1139 | 1140 | // CAPTURE THE FILE IN THE OUTPUT BUFFERS - WILL BE FLUSHED AT SCRIPT END 1141 | ob_start(); 1142 | echo $filedata; 1143 | } 1144 | 1145 | // FAILURE 1146 | else 1147 | { 1148 | die("ERROR: UNABLE TO OPEN $filename"); 1149 | } 1150 | } 1151 | 1152 | public function Logs( $zone_id = '', $log_date = '') 1153 | { 1154 | /* 1155 | will get log for the zone 1156 | */ 1157 | 1158 | if( !$this->api_key_account) 1159 | { 1160 | return array('status' =>'error' ,'code' =>'api_key_account' ,'msg'=> 'missing acount api key'); 1161 | die(); 1162 | } 1163 | 1164 | if(!$log_date) 1165 | { 1166 | $date = new DateTime(); 1167 | 1168 | //today minus 1 day... if today(2019-03-29), then date is: 2019-03-28 1169 | $date = $date->modify("-1 day"); 1170 | $date = $date->format('m-d-y'); 1171 | $log_dt = $date; 1172 | } 1173 | else if( $log_date) 1174 | { 1175 | $date = new DateTime($log_date); 1176 | $date = $date->format('m-d-y'); 1177 | $log_dt = $date; 1178 | } 1179 | 1180 | $key = $this->api_key_account; 1181 | 1182 | 1183 | 1184 | //$api_url = 'https://logging.bunnycdn.com/{mm}-{dd}-{yy}/{pull_zone_id}.log'; 1185 | $api_url = 'https://logging.bunnycdn.com/'.$log_dt.'/'.$zone_id.'.log'; 1186 | 1187 | $get_header = $this->create_header($key); 1188 | 1189 | $api_call = $this->run( array('call_method' => 'GET', 'api_url' => $api_url,'header' => $get_header , )); 1190 | 1191 | if($api_call['http_code'] !=200 ) 1192 | { 1193 | //error message 1194 | $request_array = json_decode(json_encode($api_call['data'])); 1195 | $result = array 1196 | ( 1197 | "status" => 'error', 1198 | "http_code"=>$api_call['http_code'], 1199 | "msg" => ($request_array) , 1200 | ); 1201 | return $result; 1202 | //die(); 1203 | } 1204 | else if(strlen($api_call['data']) <1 ) 1205 | { 1206 | $result = array 1207 | ( 1208 | "status" => 'error', 1209 | "http_code"=> 800, 1210 | 'msg'=> 'Ran successfully but no log data returned for the current selection.', 1211 | ); 1212 | return $result; 1213 | //die(); 1214 | } 1215 | else if($api_call['http_code'] == 200) 1216 | { 1217 | 1218 | //convert/parse it to line break 1219 | $t1 = explode("\n",$api_call['data']); 1220 | 1221 | $a1 = array(); 1222 | 1223 | foreach ($t1 as $v1) 1224 | { 1225 | if(isset($v1) && strlen($v1) > 0) 1226 | { 1227 | //parse "|" 1228 | $t2 = explode("|", $v1); 1229 | 1230 | //divide it by 1000 to convert it to php unix time 1231 | $time = round($t2[2] /1000, 0); 1232 | 1233 | $a2 = array( 1234 | 'cache_hit' => $t2[0], 1235 | 1236 | 'status' => $t2[1], 1237 | 'status_code' => $this->get_http_status_code($t2[1]), 1238 | 1239 | 'time_js' => $t2[2]*1, 1240 | 1241 | 'time_unix' => $time, 1242 | 'time_dttm' => date('Y-m-d H:i:s', $time), 1243 | 'time_dt' => date('Y-m-d', $time), 1244 | 1245 | 'bytes' => $t2[3], 1246 | 'bytes_format' => $this->format_bytes($t2[3]), 1247 | 1248 | 'zone_id' => $t2[4], 1249 | 'remote_ip' => $t2[5], 1250 | 1251 | 'referer_url' => strlen($t2[6]) > 1 ? ($t2[6]) : 'direct', 1252 | 'referer_url_raw' => $t2[6], 1253 | 1254 | 1255 | 'file_url' => $t2[7], 1256 | 1257 | 'cdn_datacenter_loc' => $t2[8], 1258 | 1259 | 'user_agent' => $t2[9], 1260 | 'request_id' => $t2[10], 1261 | 1262 | 'country' => $t2[11], 1263 | 'country_name' => $this->get_country_name($t2[11]), 1264 | ); 1265 | array_push($a1, $a2); 1266 | } 1267 | } 1268 | 1269 | $get_stats = $this->Account($key)->GetZone($zone_id)['zone_smry'][0]; 1270 | 1271 | return array( 1272 | 'status' => 'success', 1273 | "log" => $a1, 1274 | 'zone_current_monthly_bandwidth_used' => $get_stats['monthly_bandwidth_used'], 1275 | 'zone_name'=> $get_stats['zone_name'], 1276 | ); 1277 | } 1278 | 1279 | } 1280 | 1281 | //--->process functions > start 1282 | 1283 | private function create_header($api_key) 1284 | { 1285 | $header = array('Content-Type:application/json','accesskey:'.$api_key.'' ); 1286 | return $header; 1287 | } 1288 | 1289 | private function run($call_arr = array('call_method' => 'GET', 'api_url' => 'api_url','header' => array(),'post_data_array' => array() , ) ) 1290 | { 1291 | $call_method = isset($call_arr['call_method']) ? $call_arr['call_method'] : 'GET' ; 1292 | $api_url = isset($call_arr['api_url']) ? $call_arr['api_url'] : 'api_url' ; 1293 | $header = isset($call_arr['header']) ? $call_arr['header'] : '' ; 1294 | $post_data_array = isset($call_arr['post_data_array']) ? $call_arr['post_data_array'] : '' ; 1295 | 1296 | 1297 | $post_data = json_encode($post_data_array); 1298 | 1299 | $curl = curl_init($api_url); 1300 | 1301 | curl_setopt($curl, CURLOPT_HTTPHEADER,$header); 1302 | 1303 | curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $call_method); 1304 | 1305 | curl_setopt($curl, CURLOPT_URL, $api_url); 1306 | 1307 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 1308 | 1309 | curl_setopt($curl, CURLOPT_POST, 1); 1310 | curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); 1311 | 1312 | $result = curl_exec($curl); 1313 | $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); 1314 | 1315 | curl_close($curl); 1316 | 1317 | 1318 | //For error checking 1319 | if ( $result === false ) 1320 | { 1321 | return array('status' =>'error' ,'code'=> 'curl_error', 'result' => curl_error($curl) ,); 1322 | die(); 1323 | } 1324 | 1325 | return array('http_code'=> $http_code, 'data' => $result,); 1326 | } 1327 | //--->process functions > end 1328 | 1329 | 1330 | 1331 | //--->private functions > start 1332 | 1333 | 1334 | 1335 | private function fix_url($url ='') 1336 | { 1337 | return str_replace("\\", "/", $url ); 1338 | } 1339 | 1340 | private function format_bytes($bytes, $force_unit = NULL, $format = NULL, $si = TRUE) 1341 | { 1342 | // Format string 1343 | $format = ($format === NULL) ? '%01.2f %s' : (string) $format; 1344 | 1345 | // IEC prefixes (binary) 1346 | if ($si == FALSE OR strpos($force_unit, 'i') !== FALSE) 1347 | { 1348 | $units = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB'); 1349 | $mod = 1024; 1350 | } 1351 | // SI prefixes (decimal) 1352 | else 1353 | { 1354 | $units = array('B', 'kB', 'MB', 'GB', 'TB', 'PB'); 1355 | $mod = 1000; 1356 | } 1357 | // Determine unit to use 1358 | if (($power = array_search((string) $force_unit, $units)) === FALSE) 1359 | { 1360 | $power = ($bytes > 0) ? floor(log($bytes, $mod)) : 0; 1361 | } 1362 | return sprintf($format, $bytes / pow($mod, $power), $units[$power]); 1363 | } 1364 | 1365 | private function seo_file_name($file_name) 1366 | { 1367 | /* 1368 | will convert file name into seo url file name 1369 | 1370 | i.e. 1371 | $file_name = 'code with mark !@#$%^*()_+~ $$%& _03e05 122-9****.mp4'; 1372 | 1373 | //output will be 1374 | code-with-mark-03e05-122-9.mp4 1375 | 1376 | Note only use this for file names and not for folder names!!! 1377 | 1378 | */ 1379 | 1380 | $path_info = pathinfo($file_name); 1381 | $info_dir_name = preg_replace("/[\s]/", "-", strtolower($path_info['dirname']) ); 1382 | 1383 | 1384 | $info_file_name = $path_info['filename']; 1385 | $info_file_ext = $path_info['extension']; 1386 | 1387 | $string = $info_file_name ; 1388 | 1389 | $src = 'àáâãäçèéêëìíîïñòóôõöøùúûüýÿßÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝ'; 1390 | $rep = 'aaaaaceeeeiiiinoooooouuuuyysAAAAACEEEEIIIINOOOOOOUUUUY'; 1391 | // strip off accents (assuming utf8 PHP - note strtr() requires single-byte) 1392 | $string = strtr(utf8_decode($string), utf8_decode($src), $rep); 1393 | // convert to lower case 1394 | $string = strtolower($string); 1395 | // strip all but alphanumeric, whitespace, dot, underscore, hyphen 1396 | $string = preg_replace("/[^a-z0-9\s._-]/", "", $string); 1397 | // merge multiple consecutive whitespaces, dots, underscores, hyphens 1398 | $string = preg_replace("/[\s._-]+/", " ", $string); 1399 | // convert whitespaces to hyphens 1400 | $string = preg_replace("/[\s]/", "-", $string); 1401 | 1402 | 1403 | if(substr($info_dir_name,1)) 1404 | { 1405 | $file_path = $info_dir_name."/".$string.'.'.$info_file_ext; 1406 | } 1407 | else 1408 | { 1409 | $file_path = "/". $string.'.'.$info_file_ext; 1410 | } 1411 | 1412 | return $file_path; 1413 | } 1414 | 1415 | 1416 | private function get_country_name($country_code) 1417 | { 1418 | $country_name = array( 1419 | "A1" => "Anonymous Proxy", 1420 | "A2" => "Satellite Provider", 1421 | "O1" => "Other Country", 1422 | "AD" => "Andorra", 1423 | "AE" => "United Arab Emirates", 1424 | "AF" => "Afghanistan", 1425 | "AG" => "Antigua and Barbuda", 1426 | "AI" => "Anguilla", 1427 | "AL" => "Albania", 1428 | "AM" => "Armenia", 1429 | "AO" => "Angola", 1430 | "AP" => "Asia/Pacific Region", 1431 | "AQ" => "Antarctica", 1432 | "AR" => "Argentina", 1433 | "AS" => "American Samoa", 1434 | "AT" => "Austria", 1435 | "AU" => "Australia", 1436 | "AW" => "Aruba", 1437 | "AX" => "Aland Islands", 1438 | "AZ" => "Azerbaijan", 1439 | "BA" => "Bosnia and Herzegovina", 1440 | "BB" => "Barbados", 1441 | "BD" => "Bangladesh", 1442 | "BE" => "Belgium", 1443 | "BF" => "Burkina Faso", 1444 | "BG" => "Bulgaria", 1445 | "BH" => "Bahrain", 1446 | "BI" => "Burundi", 1447 | "BJ" => "Benin", 1448 | "BL" => "Saint Bartelemey", 1449 | "BM" => "Bermuda", 1450 | "BN" => "Brunei Darussalam", 1451 | "BO" => "Bolivia", 1452 | "BQ" => "Bonaire, Saint Eustatius and Saba", 1453 | "BR" => "Brazil", 1454 | "BS" => "Bahamas", 1455 | "BT" => "Bhutan", 1456 | "BV" => "Bouvet Island", 1457 | "BW" => "Botswana", 1458 | "BY" => "Belarus", 1459 | "BZ" => "Belize", 1460 | "CA" => "Canada", 1461 | "CC" => "Cocos (Keeling) Islands", 1462 | "CD" => "Congo, The Democratic Republic of the", 1463 | "CF" => "Central African Republic", 1464 | "CG" => "Congo", 1465 | "CH" => "Switzerland", 1466 | "CI" => "Cote d'Ivoire", 1467 | "CK" => "Cook Islands", 1468 | "CL" => "Chile", 1469 | "CM" => "Cameroon", 1470 | "CN" => "China", 1471 | "CO" => "Colombia", 1472 | "CR" => "Costa Rica", 1473 | "CU" => "Cuba", 1474 | "CV" => "Cape Verde", 1475 | "CW" => "Curacao", 1476 | "CX" => "Christmas Island", 1477 | "CY" => "Cyprus", 1478 | "CZ" => "Czech Republic", 1479 | "DE" => "Germany", 1480 | "DJ" => "Djibouti", 1481 | "DK" => "Denmark", 1482 | "DM" => "Dominica", 1483 | "DO" => "Dominican Republic", 1484 | "DZ" => "Algeria", 1485 | "EC" => "Ecuador", 1486 | "EE" => "Estonia", 1487 | "EG" => "Egypt", 1488 | "EH" => "Western Sahara", 1489 | "ER" => "Eritrea", 1490 | "ES" => "Spain", 1491 | "ET" => "Ethiopia", 1492 | "EU" => "Europe", 1493 | "FI" => "Finland", 1494 | "FJ" => "Fiji", 1495 | "FK" => "Falkland Islands (Malvinas)", 1496 | "FM" => "Micronesia, Federated States of", 1497 | "FO" => "Faroe Islands", 1498 | "FR" => "France", 1499 | "GA" => "Gabon", 1500 | "GB" => "United Kingdom", 1501 | "GD" => "Grenada", 1502 | "GE" => "Georgia", 1503 | "GF" => "French Guiana", 1504 | "GG" => "Guernsey", 1505 | "GH" => "Ghana", 1506 | "GI" => "Gibraltar", 1507 | "GL" => "Greenland", 1508 | "GM" => "Gambia", 1509 | "GN" => "Guinea", 1510 | "GP" => "Guadeloupe", 1511 | "GQ" => "Equatorial Guinea", 1512 | "GR" => "Greece", 1513 | "GS" => "South Georgia and the South Sandwich Islands", 1514 | "GT" => "Guatemala", 1515 | "GU" => "Guam", 1516 | "GW" => "Guinea-Bissau", 1517 | "GY" => "Guyana", 1518 | "HK" => "Hong Kong", 1519 | "HM" => "Heard Island and McDonald Islands", 1520 | "HN" => "Honduras", 1521 | "HR" => "Croatia", 1522 | "HT" => "Haiti", 1523 | "HU" => "Hungary", 1524 | "ID" => "Indonesia", 1525 | "IE" => "Ireland", 1526 | "IL" => "Israel", 1527 | "IM" => "Isle of Man", 1528 | "IN" => "India", 1529 | "IO" => "British Indian Ocean Territory", 1530 | "IQ" => "Iraq", 1531 | "IR" => "Iran, Islamic Republic of", 1532 | "IS" => "Iceland", 1533 | "IT" => "Italy", 1534 | "JE" => "Jersey", 1535 | "JM" => "Jamaica", 1536 | "JO" => "Jordan", 1537 | "JP" => "Japan", 1538 | "KE" => "Kenya", 1539 | "KG" => "Kyrgyzstan", 1540 | "KH" => "Cambodia", 1541 | "KI" => "Kiribati", 1542 | "KM" => "Comoros", 1543 | "KN" => "Saint Kitts and Nevis", 1544 | "KP" => "Korea, Democratic People's Republic of", 1545 | "KR" => "Korea, Republic of", 1546 | "KW" => "Kuwait", 1547 | "KY" => "Cayman Islands", 1548 | "KZ" => "Kazakhstan", 1549 | "LA" => "Lao People's Democratic Republic", 1550 | "LB" => "Lebanon", 1551 | "LC" => "Saint Lucia", 1552 | "LI" => "Liechtenstein", 1553 | "LK" => "Sri Lanka", 1554 | "LR" => "Liberia", 1555 | "LS" => "Lesotho", 1556 | "LT" => "Lithuania", 1557 | "LU" => "Luxembourg", 1558 | "LV" => "Latvia", 1559 | "LY" => "Libyan Arab Jamahiriya", 1560 | "MA" => "Morocco", 1561 | "MC" => "Monaco", 1562 | "MD" => "Moldova, Republic of", 1563 | "ME" => "Montenegro", 1564 | "MF" => "Saint Martin", 1565 | "MG" => "Madagascar", 1566 | "MH" => "Marshall Islands", 1567 | "MK" => "Macedonia", 1568 | "ML" => "Mali", 1569 | "MM" => "Myanmar", 1570 | "MN" => "Mongolia", 1571 | "MO" => "Macao", 1572 | "MP" => "Northern Mariana Islands", 1573 | "MQ" => "Martinique", 1574 | "MR" => "Mauritania", 1575 | "MS" => "Montserrat", 1576 | "MT" => "Malta", 1577 | "MU" => "Mauritius", 1578 | "MV" => "Maldives", 1579 | "MW" => "Malawi", 1580 | "MX" => "Mexico", 1581 | "MY" => "Malaysia", 1582 | "MZ" => "Mozambique", 1583 | "NA" => "Namibia", 1584 | "NC" => "New Caledonia", 1585 | "NE" => "Niger", 1586 | "NF" => "Norfolk Island", 1587 | "NG" => "Nigeria", 1588 | "NI" => "Nicaragua", 1589 | "NL" => "Netherlands", 1590 | "NO" => "Norway", 1591 | "NP" => "Nepal", 1592 | "NR" => "Nauru", 1593 | "NU" => "Niue", 1594 | "NZ" => "New Zealand", 1595 | "OM" => "Oman", 1596 | "PA" => "Panama", 1597 | "PE" => "Peru", 1598 | "PF" => "French Polynesia", 1599 | "PG" => "Papua New Guinea", 1600 | "PH" => "Philippines", 1601 | "PK" => "Pakistan", 1602 | "PL" => "Poland", 1603 | "PM" => "Saint Pierre and Miquelon", 1604 | "PN" => "Pitcairn", 1605 | "PR" => "Puerto Rico", 1606 | "PS" => "Palestinian Territory", 1607 | "PT" => "Portugal", 1608 | "PW" => "Palau", 1609 | "PY" => "Paraguay", 1610 | "QA" => "Qatar", 1611 | "RE" => "Reunion", 1612 | "RO" => "Romania", 1613 | "RS" => "Serbia", 1614 | "RU" => "Russian Federation", 1615 | "RW" => "Rwanda", 1616 | "SA" => "Saudi Arabia", 1617 | "SB" => "Solomon Islands", 1618 | "SC" => "Seychelles", 1619 | "SD" => "Sudan", 1620 | "SE" => "Sweden", 1621 | "SG" => "Singapore", 1622 | "SH" => "Saint Helena", 1623 | "SI" => "Slovenia", 1624 | "SJ" => "Svalbard and Jan Mayen", 1625 | "SK" => "Slovakia", 1626 | "SL" => "Sierra Leone", 1627 | "SM" => "San Marino", 1628 | "SN" => "Senegal", 1629 | "SO" => "Somalia", 1630 | "SR" => "Suriname", 1631 | "SS" => "South Sudan", 1632 | "ST" => "Sao Tome and Principe", 1633 | "SV" => "El Salvador", 1634 | "SX" => "Sint Maarten", 1635 | "SY" => "Syrian Arab Republic", 1636 | "SZ" => "Swaziland", 1637 | "TC" => "Turks and Caicos Islands", 1638 | "TD" => "Chad", 1639 | "TF" => "French Southern Territories", 1640 | "TG" => "Togo", 1641 | "TH" => "Thailand", 1642 | "TJ" => "Tajikistan", 1643 | "TK" => "Tokelau", 1644 | "TL" => "Timor-Leste", 1645 | "TM" => "Turkmenistan", 1646 | "TN" => "Tunisia", 1647 | "TO" => "Tonga", 1648 | "TR" => "Turkey", 1649 | "TT" => "Trinidad and Tobago", 1650 | "TV" => "Tuvalu", 1651 | "TW" => "Taiwan", 1652 | "TZ" => "Tanzania, United Republic of", 1653 | "UA" => "Ukraine", 1654 | "UG" => "Uganda", 1655 | "UM" => "United States Minor Outlying Islands", 1656 | "US" => "United States", 1657 | "UY" => "Uruguay", 1658 | "UZ" => "Uzbekistan", 1659 | "VA" => "Holy See (Vatican City State)", 1660 | "VC" => "Saint Vincent and the Grenadines", 1661 | "VE" => "Venezuela", 1662 | "VG" => "Virgin Islands, British", 1663 | "VI" => "Virgin Islands, U.S.", 1664 | "VN" => "Vietnam", 1665 | "VU" => "Vanuatu", 1666 | "WF" => "Wallis and Futuna", 1667 | "WS" => "Samoa", 1668 | "YE" => "Yemen", 1669 | "YT" => "Mayotte", 1670 | "ZA" => "South Africa", 1671 | "ZM" => "Zambia", 1672 | "ZW" => "Zimbabwe", 1673 | ); 1674 | //return $country_name[$country_code]; 1675 | foreach ($country_name as $k1 => $v1) 1676 | { 1677 | if($k1 == $country_code) 1678 | { 1679 | return $v1; 1680 | } 1681 | } 1682 | } 1683 | 1684 | private function get_http_status_code($code) 1685 | { 1686 | $status_code = array( 1687 | // 1XX 1688 | "100" => "Continue", 1689 | "101" => "Switching Protocols", 1690 | "102" => "Processing", 1691 | "103" => "Early Hints", 1692 | // 2XX 1693 | "200" => "OK", 1694 | "201" => "Created", 1695 | "202" => "Accepted", 1696 | "203" => "Non-Authoritative Information", 1697 | "204" => "No Content", 1698 | "206" => "Partial Content", 1699 | "207" => "Multi-Status", 1700 | "208" => "Already Reported", 1701 | "226" => "IM Used", 1702 | // 3XX 1703 | "300" => "Multiple Choices", 1704 | "301" => "Moved Permanently", 1705 | "302" => "Found", 1706 | "303" => "See Other", 1707 | "304" => "Not Modified", 1708 | "305" => "Use Proxy", 1709 | "306" => "Switch Proxy", 1710 | "307" => "Temporary Redirect", 1711 | "308" => "Permanent Redirect", 1712 | // 4XX 1713 | "400" => "Bad Request", 1714 | "401" => "Unauthorized", 1715 | "402" => "Payment Required", 1716 | "403" => "Forbidden", 1717 | "404" => "Not Found", 1718 | "405" => "Method Not Allowed", 1719 | "406" => "Not Acceptable", 1720 | "407" => "Proxy Authentication Required", 1721 | "408" => "Request Timeout", 1722 | "409" => "Conflict", 1723 | "410" => "Gone", 1724 | "411" => "Length Required", 1725 | "412" => "Precondition Failed", 1726 | "413" => "Payload Too Large", 1727 | "414" => "URI Too Long", 1728 | "415" => "Unsupported Media Type", 1729 | "416" => "Range Not Satisfiable", 1730 | "417" => "Expectation Failed", 1731 | "418" => "I'm a teapot", 1732 | "421" => "Misdirected Request", 1733 | "422" => "Unprocessable Entity", 1734 | "423" => "Locked", 1735 | "424" => "Failed Dependency", 1736 | "426" => "Upgrade Required", 1737 | "428" => "Precondition Required", 1738 | "429" => "Too Many Requests", 1739 | "431" => "Request Header Fields Too Large", 1740 | "451" => "Unavailable For Legal Reasons", 1741 | 1742 | // 5XX 1743 | "500" => "Internal Server Error", 1744 | "501" => "Not Implemented", 1745 | "502" => "Bad Gateway", 1746 | "503" => "Service Unavailable", 1747 | "504" => "Gateway Timeout", 1748 | "505" => "HTTP Version Not Supported", 1749 | "506" => "Variant Also Negotiates", 1750 | "507" => "Insufficient Storage", 1751 | "508" => "Loop Detected", 1752 | "510" => "Not Extended", 1753 | "511" => "Network Authentication Required", 1754 | ); 1755 | 1756 | foreach ($status_code as $k1 => $v1) 1757 | { 1758 | if($k1 == $code) 1759 | { 1760 | return $v1; 1761 | } 1762 | } 1763 | } 1764 | 1765 | 1766 | //--->private functions > end 1767 | } 1768 | --------------------------------------------------------------------------------