六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 984|回复: 0

PHP实例关于FTP疑问,图片上传到图片服务器上都有哪些方...

[复制链接]
 楼主| 发表于 2014-2-18 13:26:10 | 显示全部楼层 |阅读模式
PHP实例关于FTP疑问,图片上传到图片服务器上都有哪些方法?-it技术论坛-it论坛-计算机论坛

我用过的方法,供参考:
1.在iframe里面用另一表单上传图片,表单地址是图片服务器;

2.同样是上传图片后首先是存放在运行程序的服务器的临时目录里,服务器有一个对图片进行压缩、缩放等处理的shell脚本进程,这个脚本的处理完图片后,通过rsync将处理好的图片推送到图片服。


可以采用程序去处理,参考一下CI的一个类库(Ftp.php),源代码如下:

  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * CodeIgniter
  4. *
  5. * An open source application development framework for PHP 5.1.6 or newer
  6. *
  7. * @package CodeIgniter
  8. * @author ExpressionEngine Dev Team
  9. * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
  10. * @license http://codeigniter.com/user_guide/license.html
  11. * @link http://codeigniter.com
  12. * @since Version 1.0
  13. * @filesource
  14. */


  15. // ------------------------------------------------------------------------


  16. /**
  17. * FTP Class
  18. *
  19. * @package CodeIgniter
  20. * @subpackage Libraries
  21. * @category Libraries
  22. * @author ExpressionEngine Dev Team
  23. * @link http://codeigniter.com/user_guide/libraries/ftp.html
  24. */
  25. class CI_FTP {


  26. var $hostname = '';
  27. var $username = '';
  28. var $password = '';
  29. var $port = 21;
  30. var $passive = TRUE;
  31. var $debug = FALSE;
  32. var $conn_id = FALSE;


  33. /**
  34. * Constructor - Sets Preferences
  35. *
  36. * The constructor can be passed an array of config values
  37. */
  38. public function __construct($config = array())
  39. {
  40. if (count($config) > 0)
  41. {
  42. $this->initialize($config);
  43. }


  44. log_message('debug', "FTP Class Initialized");
  45. }


  46. // --------------------------------------------------------------------


  47. /**
  48. * Initialize preferences
  49. *
  50. * @access public
  51. * @param array
  52. * @return void
  53. */
  54. function initialize($config = array())
  55. {
  56. foreach ($config as $key => $val)
  57. {
  58. if (isset($this->$key))
  59. {
  60. $this->$key = $val;
  61. }
  62. }


  63. // Prep the hostname
  64. $this->hostname = preg_replace('|.+?://|', '', $this->hostname);
  65. }


  66. // --------------------------------------------------------------------


  67. /**
  68. * FTP Connect
  69. *
  70. * @access public
  71. * @param array the connection values
  72. * @return bool
  73. */
  74. function connect($config = array())
  75. {
  76. if (count($config) > 0)
  77. {
  78. $this->initialize($config);
  79. }


  80. if (FALSE === ($this->conn_id = @ftp_connect($this->hostname, $this->port)))
  81. {
  82. if ($this->debug == TRUE)
  83. {
  84. $this->_error('ftp_unable_to_connect');
  85. }
  86. return FALSE;
  87. }


  88. if ( ! $this->_login())
  89. {
  90. if ($this->debug == TRUE)
  91. {
  92. $this->_error('ftp_unable_to_login');
  93. }
  94. return FALSE;
  95. }


  96. // Set passive mode if needed
  97. if ($this->passive == TRUE)
  98. {
  99. ftp_pasv($this->conn_id, TRUE);
  100. }


  101. return TRUE;
  102. }
复制代码
PHP实例关于FTP疑问,图片上传到图片服务器上都有哪些方法?-it技术论坛-it论坛-计算机论坛
本文摘自:http://www.yl1001.com/yw.htm?doa ... id=7721372640348109

该会员没有填写今日想说内容.
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表