Hke.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. if( !defined('BASEPATH') )
  3. {
  4. exit( 'No direct script access allowed' );
  5. }
  6. class Ftpup
  7. {
  8. public function __construct()
  9. {
  10. set_time_limit(0);
  11. }
  12. public function up($file_path, $file_name)
  13. {
  14. if( Ftp_Is == 2 )
  15. {
  16. $data["Token"] = Ftp_Token;
  17. $data["file"] = "@" . $file_path;
  18. $data["deadline"] = time() + 60;
  19. $data["aid"] = Ftp_Pid;
  20. $data["from"] = "file";
  21. $json = $this->uppost("http://up.tietuku.com/", $data);
  22. $arr = json_decode($json, true);
  23. if( !empty($arr["linkurl"]) )
  24. {
  25. unlink($file_path);
  26. return $arr["linkurl"] . "#ttk";
  27. }
  28. return false;
  29. }
  30. $ci =& get_instance();
  31. $ci->load->library("ftp");
  32. if( $ci->ftp->connect(array( "port" => Ftp_Port, "debug" => false, "passive" => Ftp_Ive, "hostname" => Ftp_Server, "username" => Ftp_User, "password" => Ftp_Pass )) )
  33. {
  34. $Dirs = Ftp_Dir;
  35. if( substr($Dirs, -1) == "/" )
  36. {
  37. $Dirs = substr($Dirs, 0, -1);
  38. }
  39. $dir = $Dirs . "/" . date("Ymd") . "/";
  40. $ci->ftp->mkdir($dir);
  41. if( $ci->ftp->upload($file_path, $dir . $file_name, SITE_ATTACH_MODE, 509) )
  42. {
  43. unlink($file_path);
  44. $ci->ftp->close();
  45. return str_replace($Dirs, "", $dir) . $file_name;
  46. }
  47. return false;
  48. }
  49. return false;
  50. }
  51. public function del($file_path)
  52. {
  53. $ci =& get_instance();
  54. $ci->load->library("ftp");
  55. if( substr($file_path, 0, 1) == "/" )
  56. {
  57. $file_path = substr($file_path, 1);
  58. }
  59. if( $ci->ftp->connect(array( "port" => Ftp_Port, "debug" => false, "passive" => Ftp_Ive, "hostname" => Ftp_Server, "username" => Ftp_User, "password" => Ftp_Pass )) )
  60. {
  61. $Dirs = Ftp_Dir;
  62. if( substr($Dirs, -1) == "/" )
  63. {
  64. $Dirs = substr($Dirs, 0, -1);
  65. }
  66. $path = $Dirs . "/" . $file_path;
  67. $res = $ci->ftp->delete_file("." . $path);
  68. $ci->ftp->close();
  69. if( !$res )
  70. {
  71. return false;
  72. }
  73. return true;
  74. }
  75. return NULL;
  76. }
  77. public function uppost($url, $post_data)
  78. {
  79. $ch = curl_init();
  80. curl_setopt($ch, CURLOPT_URL, $url);
  81. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  82. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  83. curl_setopt($ch, CURLOPT_POST, 1);
  84. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  85. $output = curl_exec($ch);
  86. curl_close($ch);
  87. return $output;
  88. }
  89. }