//CI---FTP配置 private function ftpConf(){ //FTP上傳文件的基本配置 $this->load->config('ftp'); $this->load->library('ftp'); $config = $this->config->config; $conf['hostname'] = $config['FTPHOST']; $conf['username'] = $config['FTPUSER']; $conf['password'] = $config['FTPPASS']; $conf['port'] = $config['FTPPORT']; $conf['debug'] = $config['FTPDEBUG']; $this->ftp->connect($conf); // return $conf['hostname']; }
//FTP---根據路徑上傳 private function ftpUpload($url,$path = 'logo'){ $imgname = getImgName().substr($url,strripos($url,'.')); $this->ftpConf(); $rempath = $url; $picpath = 'xcy/'.$path.'/'.date('Ym'); $this->ftp->rec_mkdir($picpath); //遞歸建立目錄 $bool = $this->ftp->upload($rempath, $picpath.'/'.$imgname); //ftp核心 $imgPath = false; if($bool){ $imgPath = 'xcy/'.$path.'/'.date('Ym').'/'.$imgname; } /*else{ echo $this->upload->display_errors(); }*/ $this->ftp->close(); return $imgPath; }
//遠程圖片本地化 private function getRemoteFile($url,$path = 'logo'){ set_time_limit(0); if($url == ""){ return false; } $filename = getImgName().substr($url,strripos($url,'.')); // 檢查路徑是否存在,如不存在則建立 // $dir = './upload/'.$path.'/'.date('Ym').'/'; // 檢查路徑是否存在,如不存在則建立(本目錄指向根目錄同級目錄) $dir = realpath(dirname(__FILE__).'/../').'/img.com/'.$path.'/'.date('Ym').'/'; checkdir($dir); ob_start();//打開輸出 readfile($url);//輸出圖片文件 $img = ob_get_contents();//獲得瀏覽器輸出 ob_end_clean();//清除輸出並關閉 $size = strlen($img);//獲得圖片大小 $fp2 = @fopen($dir.$filename, "a"); if(fwrite($fp2,$img) === false){ log_message("error",'dolwload image falied. Error Info: 沒法寫入圖片'); exit(); } fclose($fp2); return 'upload/'.$path.'/'.date('Ym').'/'.$filename; }
//CI---FTP文件,自定義方法 function rec_mkdir($path) { $path_arr = explode('/',$path); // 取目錄數組 $path_arr = array_filter($path_arr); //過濾空目錄 $path_div = count($path_arr); // 取層數 foreach($path_arr as $val) // 建立目錄 { if(@ftp_chdir($this->conn_id,$val) == FALSE) { $tmp = @ftp_mkdir($this->conn_id,$val); if($tmp == FALSE) { echo "目錄建立失敗,請檢查權限及路徑是否正確!"; exit; } @ftp_chdir($this->conn_id,$val); } } for($i=1;$i<=$path_div;$i++) // 回退到根 { @ftp_cdup($this->conn_id); } }
//CI-FTP-LANG(語言包) $lang['ftp_no_connection'] = "Unable to locate a valid connection ID. Please make sure you are connected before peforming any file routines."; $lang['ftp_unable_to_connect'] = "Unable to connect to your FTP server using the supplied hostname."; $lang['ftp_unable_to_login'] = "Unable to login to your FTP server. Please check your username and password."; $lang['ftp_unable_to_makdir'] = "Unable to create the directory you have specified."; $lang['ftp_unable_to_changedir']= "Unable to change directories."; $lang['ftp_unable_to_chmod'] = "Unable to set file permissions. Please check your path. Note: This feature is only available in PHP 5 or higher."; $lang['ftp_unable_to_upload'] = "Unable to upload the specified file. Please check your path."; $lang['ftp_unable_to_download'] = "Unable to download the specified file. Please check your path."; $lang['ftp_no_source_file'] = "Unable to locate the source file. Please check your path."; $lang['ftp_unable_to_rename'] = "Unable to rename the file."; $lang['ftp_unable_to_delete'] = "Unable to delete the file."; $lang['ftp_unable_to_move'] = "Unable to move the file. Please make sure the destination directory exists.";