将图像上传到另一个服务器编码器


upload image to another server codeigniter

我正在做一个codeigniter网站。我的客户有两个网站。但他需要处理两个网站由一个管理员。我通过使用多个数据库连接将数据上传到两个数据库。但我的问题是如何上传图像到另一个服务器。

您可以使用CURL。这样就可以了。

$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('file' => '@/path/to/file.txt'));
curl_setopt($ch, CURLOPT_URL, 'http://server2/upload.php');
curl_exec($ch);
curl_close($ch);

然后可以将server2部分作为常规文件上传来处理。有关这些选项的更多信息,请参见curl_setopt()。

你可以

  1. 将图像存储到数据库
  2. 挂载远程文件系统并保存为普通文件
  3. 通过SSH/FTP连接并发送文件

CodeIgniter提供FTP类来将文件传输到远程服务器。使用CodeIgniter的上传和FTP库,您可以轻松地将图像或文件上传到另一台服务器。

这是从本地服务器上传图像到远程服务器的代码。

$fileName = 'image.jpg';
//File path at local server
$source = 'uploads/'.$fileName;
//Load codeigniter FTP class
$this->load->library('ftp');
//FTP configuration
$ftp_config['hostname'] = 'ftp.example.com'; 
$ftp_config['username'] = 'ftp_username';
$ftp_config['password'] = 'ftp_password';
$ftp_config['debug']    = TRUE;
//Connect to the remote server
$this->ftp->connect($ftp_config);
//File upload path of remote server
$destination = '/assets/'.$fileName;
//Upload file to the remote server
$this->ftp->upload($source, ".".$destination);
//Close FTP connection
$this->ftp->close();

完整的源代码和教程我已经找到了从这里- CodeIgniter:上传文件到远程服务器

相关文章: