簡體   English   中英

將圖像上傳到另一個服務器codeigniter

[英]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:將文件上傳到遠程服務器

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM