From 43de485436443f33968e1f5db22487ce10f0c9cb Mon Sep 17 00:00:00 2001 From: zero Date: Thu, 17 May 2007 04:02:21 +0000 Subject: [PATCH] git-svn-id: http://xe-core.googlecode.com/svn/trunk@1448 201d5d3c-b55e-5fd7-737f-ddc643e51545 --- classes/file/FileHandler.class.php | 29 ++++++++++++++++++++++++ modules/importer/importer.controller.php | 17 +++++++------- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/classes/file/FileHandler.class.php b/classes/file/FileHandler.class.php index 01f8fe5b8..c2c6c5456 100644 --- a/classes/file/FileHandler.class.php +++ b/classes/file/FileHandler.class.php @@ -125,6 +125,35 @@ return sprintf("%0.2fMB",$size / (1024*1024)); } + /** + * @brief 원격파일을 다운받아서 특정 위치에 저장 + **/ + function getRemoteFile($url, $target_filename) { + $url_info = parse_url($url); + + if(!$url_info['port']) $url_info['port'] = 80; + + $fp = fsockopen($url_info['host'], $url_info['port']); + if(!$fp) return; + + $header = sprintf("GET %s HTTP/1.0\r\nHost: %s\r\nReferer: %s://%s\r\n\r\n", $url_info['path'], $url_info['host'], $url_info['scheme'], $url_info['host']); + fwrite($fp, $header); + + $ft = fopen($target_filename, 'w'); + if(!$ft) return; + + $begin = false; + while(!feof($fp)) { + $str = fgets($fp, 1024); + if($begin) fwrite($ft, $str); + if(!trim($str)) $begin = true; + } + fclose($ft); + fclose($fp); + + return true; + } + /** * @brief 특정 이미지 파일을 특정 위치로 옮김 (옮길때 이미지의 크기를 리사이징할 수 있음..) **/ diff --git a/modules/importer/importer.controller.php b/modules/importer/importer.controller.php index d661ac4a1..c9ec6027f 100644 --- a/modules/importer/importer.controller.php +++ b/modules/importer/importer.controller.php @@ -237,16 +237,17 @@ if($files && !is_array($files)) $files = array($files); if(count($files)) { foreach($files as $key => $val) { - $filename = $val->attrs->name; - $downloaded_count = (int)$val->downloaded_count->body; - $file_buff = base64_decode($val->buff->body); + $filename = $val->filename->body; + $url = $val->url->body; + $download_count = (int)$val->download_count->body; $tmp_filename = './files/cache/tmp_uploaded_file'; - FileHandler::writeFile($tmp_filename, $file_buff); - - $file_info['tmp_name'] = $tmp_filename; - $file_info['name'] = $filename; - $this->oFileController->insertFile($file_info, $this->module_srl, $args->document_srl, $downloaded_count); + if(FileHandler::getRemoteFile($url, $tmp_filename)) { + $file_info['tmp_name'] = $tmp_filename; + $file_info['name'] = $filename; + $this->oFileController->insertFile($file_info, $this->module_srl, $args->document_srl, $download_count); + } + @unlink($tmp_filename); } }