2013-05-29 103 views
2

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

回答

2

您可以为此使用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); 

然后,您可以处理的服务器2部分作为普通的文件上传。有关这些选项的更多信息,请参阅curl_setopt()

+0

致命错误:调用未定义的函数curl_init() – Ammu

+0

转到你的'php.ini'文件并删除';从'标志以下行的开头: '; extension = php_curl.dll' –

+0

@Ammu Aishrya Rai Ko Kangana Ranaut ne answer diya :) –

1

你可以在数据库

  1. 将图像存储
  2. 挂载远程文件系统,并保存为正常文件
  3. 通过SSH/FTP连接和发送文件
0

笨提供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 : Upload file to remote server