2012-11-07 35 views
0

我有一個項目,我想用笨來調整上傳的圖片,並保存到遠程服務器笨調整圖像並保存到遠程服務器

我可以成功做到以下(所有我的本地機器上):

  1. 獲得上傳的圖片
  2. 保存到一個文件夾中TMP
  3. 調整在tmp文件夾
  4. 將圖像保存到最終目的地文件夾。

但是,我想再向前看一步。我想從tmp獲取圖像,調整大小並保存到遠程服務器。這裏是我假設它不會工作的示例代碼。

$config['image_library'] = 'gd2'; 
$config['source_image'] = '/tmp/sample.jpg'; 
$config['create_thumb'] = TRUE; 
$config['maintain_ratio'] = TRUE; 
$config['width'] = 80; 
$config['height'] = 60; 
$config['new_image'] = 'ftp://xx.xx.xxx.xxx/tmp/sample.jpg'; // can i do this? 
$config['thumb_marker'] = ''; 

$ftpconfig['hostname'] = 'xx.xx.xxx.xxx'; 
$ftpconfig['username'] = 'name'; 
$ftpconfig['password'] = 'password'; 
$ftpconfig['debug'] = TRUE; 

$this->ftp->connect($ftpconfig); 

// and can I call CI to resize it and save to a ftp server after connent ftp? 
$this->image_lib->initialize($config); 
$this->image_lib->resize(); 
$this->image_lib->clear(); 

$this->ftp->close(); 
+0

http://stackoverflow.com/questions/13154787/image-resize-before-uploading-in-codeigniter-php/13155566#13155566檢查我的答案那裏,你可能需要閱讀它的意見。這就是你想要的。 –

回答

1

你需要上傳的文件,現在你不使用FTP庫文件的上傳方式保存在服務器上後,你必須上傳

$this->ftp->upload('/local/path/to/myfile.html', '/public_html/myfile.html', 'ascii', 0775); 

請用戶指南ftp類