2012-02-21 4 views
1

/config/upload.php를 사용하여 업로드를 구성하고 싶습니다. 그러나 일부 설정 항목은 상황에 따라 다릅니다. 대부분의 경우 업로드 디렉토리가 동적으로 설정됩니다 (예 : 사용자 ID 통합, 임의 폴더 사용 등). 경우에 따라 업로드 할 수있는 파일 형식이 다를 수 있습니다 (예 : 한 사례의 사진 만, 다른 경우의 동영상 만).CodeIgniter, upload and config

/config/upload.php에 일반 설정 항목을 넣고 나중에 특정 항목을 추가/덮어 쓸 수 있습니까? 그렇다면 어떻게?

답변

7

업로드하는 데 사용중인 컨트롤러에서 업로드 라이브러리의 옵션을 다시 정의하고 다시 초기화하면됩니다.

$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); 

// Alternately you can set preferences by calling the initialize function. Useful if you auto-load the class: 
$this->upload->initialize($config); 
이 좀 더이 가능하다 당신이에보고 한 후 그

UPDATE에게

를 다시 실행해야합니다, 그래서 당신은 내가 확신 모든 사전 정의 된 설정 항목을 잃게됩니다

. Upload 라이브러리를 보면 내부에 함수가있어 set 변수 중 일부가 있습니다. 모두에 대해 set 기능이 없으며 모두 사용할 수있는 set 기능이 아닐 수 있습니다. 그래서 당신은 이런 것을 할 수 있습니다. 같이

$this->load->library("Upload"); // loads upload library with predefined config items in config/upload.php 

//to change upload path 
$this->upload->set_upload_path("new location"); 
//CANNOT DO THIS BECAUSE ITS USED IN do_upload function you would need to extend the upload library and create your own set function. 
$this->upload->set_filename("new filename"); 

$this->upload->do_upload(); 

기타 값

내가하고 싶은 게 아니에요
set_max_filesize 
set_max_filename 
set_max_width 
set_max_height 
set_allowed_types 
+0

을 설정하는 데 사용할 수 있습니다. 난 그냥 특정 구성 값을 무시하고 싶습니다. 업로드 할 때마다이 작업을 수행하려고하면 /config/upload.php를 사용할 필요가 없습니다. – StackOverflowNewbie

+0

@StackOverflowNewbie 내 대답을 업데이트했습니다 – Henesnarfel

+0

@Henesnarfel 그 위대한 일했습니다. 고맙습니다. :) 허용 된 파일 형식을 재정의하기 위해 abmove 메서드를 사용했습니다. – fl3x7