[英]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() 。
您可以
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:将文件上传到远程服务器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.