我正在做一个codeigniter网站。我的客户有两个网站。但他需要由一个管理员处理这两个站点。我已经通过使用多个数据库连接将数据上传到两个数据库。但我的问题是如何将图像上传到另一台服务器。有可能吗?
问问题
4631 次
3 回答
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);
然后,您可以将 server2 部分作为常规文件上传处理。有关这些选项的更多信息,请参阅curl_setopt()。
于 2013-05-29T10:48:53.150 回答
1
你可以
- 将图像存储在数据库中
- 挂载远程文件系统并保存为普通文件
- 通过 SSH/FTP 连接并发送文件
于 2013-05-29T10:49:34.997 回答
1
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:将文件上传到远程服务器
于 2015-09-12T08:36:55.147 回答