| 제목 | 파일 업로드 기능 접근 IP주소 변경 방법에 대해서 질문드립니다. | ||
|---|---|---|---|
| 카테고리 | CI 2, 3 | ||
| 글쓴이 | Linus | 작성시각 | 2019/03/30 00:38:51 | 
|  | |||
| 안녕하세요. 파일 업로드 기능과 관련하여 질문드립니다. 모든 설정은 코드이그나이터 메뉴얼에서 요구하는 사항에 따라 작성했습니다. (http://www.ciboard.co.kr/user_guide/kr/libraries/file_uploading.html#class-reference) 
 폴더 구조, 파일명, 파일 내용 모두 메뉴얼에서 요구하는 사항에 따라서 작성했는데요, 문제는, 서버의 ip가 다르다는 겁니다. 해당 서버에 접속할 떄 외부에서 사용하는 IP는 123.456.789.012라면, 실제 해당 서버의 IP는 111.222.111.201로 되어 있는 것과 같이 다른 IP 주소를 요구합니다. 
 메뉴얼에 따라서 그대로 작성하면 파일 업로드 기능이 실제 IP 주소인 111.222.111.201(ifconfig를 통해서 확인할 수 있는 IP)를 이용하여 접근을 시도하면서 타임아웃 에러가 발생합니다. 
 혹시 파일 업로드를 위한 라이브러리가 사용하는 IP 주소를 변경할 수 있는 방법이 있을까요? 외부에서는 123.456.789.012(가비아에서 제공해 준 IP)를 이용해서만 접근이 가능하게 되어 있습니다. 
 감사합니다! ----- upload_form.php <view> ----- 
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<?php echo $error;?>
<?php echo form_open_multipart('upload/do_upload');?>
<input type="file" name="userfile" size="20" />
<br /><br />
<input type="submit" value="upload" />
</form>
</body>
</html>
 ----- upload_success.php <view> ----- 
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<h3>Your file was successfully uploaded!</h3>
<ul>
<?php foreach ($upload_data as $item => $value):?>
<li><?php echo $item;?>: <?php echo $value;?></li>
<?php endforeach; ?>
</ul>
<p><?php echo anchor('upload', 'Upload Another File!'); ?></p>
</body>
</html>
 ----- upload.php <controller> ----- 
<?php
class Upload extends CI_Controller {
        public function __construct()
        {
                parent::__construct();
                $this->load->helper(array('form', 'url'));
        }
        public function index()
        {
                $this->load->view('upload_form', array('error' => ' ' ));
        }
        public function do_upload()
        {
                $config['upload_path']          = './uploads/';
                $config['allowed_types']        = 'gif|jpg|png';
                $config['max_size']             = 100;
                $config['max_width']            = 1024;
                $config['max_height']           = 768;
                $this->load->library('upload', $config);
                if ( ! $this->upload->do_upload())
                {
                        $error = array('error' => $this->upload->display_errors());
                        $this->load->view('upload_form', $error);
                }
                else
                {
                        $data = array('upload_data' => $this->upload->data());
                        $this->load->view('upload_success', $data);
                }
        }
}
?>
 | |||
| 다음글 | jQuery 를 사용하고자 합니다. (3) | ||
| 이전글 | view호출 질문 (2) | ||
| 
                                Linus
                                /
                                2019/03/30 00:47:48 /
                                추천
                                0
                             | 
정말 죄송합니다.
조금만 더 찾아보면 알 수 있는 내용이었는데...
개발자 모드로 확인해보니
<?php echo form_open_multipart('upload/do_upload');?>이 부분이 자동으로 IP 주소를 찍어서 action 속성을 구성해주고 있었네요
이 헬퍼를 이용하지 않고 직접 작성하면 원하는 결과를 얻을 수 있을 것 같습니다!