Ftp.php 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace app\common\extend\upload;
  3. use app\common\util\Ftp as ftpOper;
  4. class Ftp
  5. {
  6. public $name = 'FTP存储';
  7. public $ver = '1.0';
  8. private $config = [];
  9. public function __construct($config = []) {
  10. $this->config = $config;
  11. }
  12. public function submit($file_path)
  13. {
  14. $ftp = new ftpOper();
  15. $ftp_config = [
  16. 'ftp_host'=>$GLOBALS['config']['upload']['api']['ftp']['host'],
  17. 'ftp_port'=>$GLOBALS['config']['upload']['api']['ftp']['port'],
  18. 'ftp_user'=>$GLOBALS['config']['upload']['api']['ftp']['user'],
  19. 'ftp_pwd' =>$GLOBALS['config']['upload']['api']['ftp']['pwd'],
  20. 'ftp_dir'=>$GLOBALS['config']['upload']['api']['ftp']['path'],
  21. ];
  22. $ftp->config($ftp_config);
  23. $ftp->connect();
  24. $a = $ftp->put(ROOT_PATH. $file_path, $file_path);
  25. $filePath = ROOT_PATH . $file_path;
  26. empty($this->config['keep_local']) && @unlink($filePath);
  27. return $GLOBALS['config']['upload']['api']['ftp']['url'] . '/' . $file_path;
  28. }
  29. }