2010-04-27 4 views
1

일부 매개 변수가 필요하며 파일을 업로드해야하는 도우미를 만들었습니다.이 기능은 zip 파일이 아닌 이미지 용으로 작동합니다. 나는 구글에서 검색, 심지어 MY_upload.php 추가 - 그러나 우편 배열이 비어codeigniter에서 zip 파일 업로드가 작동하지 않습니다.

그러나 나는 아직도 문제가 내가 업로드 된 파일의 배열을 표시 인 print_r을 사용했다>http://codeigniter.com/bug_tracker/bug/6780/는 이미지가 잘입니다 :

Array 
(
    [file_name] => 
    [file_type] => 
    [file_path] => 
    [full_path] => 
    [raw_name] => 
    [orig_name] => 
    [file_ext] => 
    [file_size] => 
    [is_image] => 
    [image_width] => 
    [image_height] => 
    [image_type] => 
    [image_size_str] => 
) 

Array 
(
    [file_name] => 2385b959279b5e3cd451fee54273512c.png 
    [file_type] => image/png 
    [file_path] => I:/wamp/www/e-commerce/sources/images/ 
    [full_path] => I:/wamp/www/e-commerce/sources/images/2385b959279b5e3cd451fee54273512c.png 
    [raw_name] => 2385b959279b5e3cd451fee54273512c 
    [orig_name] => 1269770869_Art_Artdesigner.lv_.png 
    [file_ext] => .png 
    [file_size] => 15.43 
    [is_image] => 1 
    [image_width] => 113 
    [image_height] => 128 
    [image_type] => png 
    [image_size_str] => width="113" height="128" 
) 

이 함수 도우미

function multiple_upload($name = 'userfile', $upload_dir = 'sources/images/', $allowed_types = 'gif|jpg|jpeg|jpe|png', $size) 
    { 
     $CI =& get_instance(); 

     $config['upload_path'] = realpath($upload_dir); 
     $config['allowed_types'] = $allowed_types; 
     $config['max_size']  = $size; 
     $config['overwrite']  = FALSE; 
     $config['encrypt_name'] = TRUE; 

      $ffiles = $CI->upload->data(); 

      echo "<pre>"; 
      print_r($ffiles); 
      echo "</pre>"; 
      $CI->upload->initialize($config); 
      $errors = FALSE; 

      if(!$CI->upload->do_upload($name))://I believe this is causing the problem but I'm new to codeigniter so no idea where to look for errors 
       $errors = TRUE; 
      else: 
       // Build a file array from all uploaded files 
       $files = $CI->upload->data(); 
      endif; 


      // There was errors, we have to delete the uploaded files 
      if($errors):     
       @unlink($files['full_path']); 
       return false; 
      else: 
       return $files; 
      endif; 

    }//end of multiple_upload() 

이며,이 내 컨트롤러 코드입니다

if(!$s_thumb = multiple_upload('small_thumb', 'sources/images/', 'gif|jpg|jpeg|jpe|png', 1024)): //http://www.matisse.net/bitcalc/ 
    $data['feedback'] = '<div class="error">Could not upload the small thumbnail!</div>'; 
    $error = TRUE; 
endif; 
if(!$main_file = multiple_upload('main_file', 'sources/items/', 'zip', 307200)): 
    $data['feedback'] = '<div class="error">Could not upload the main file!</div>'; 
    $error = TRUE; 
endif; 
+1

해결책을 찾았습니다 -> http://codeigniter.com/forums/viewthread/149027/ 허용되는 MIME 유형에 강제 다운로드 추가 – Christophe

+0

답변을 답변으로 추가하고 승인해야합니다. 여기에 "답이 없음"에 나타나지 않습니다. :) – Robert

+0

네,하지만 당신은 항상 그 일을 할 수있을 때까지 24 시간을 기다려야합니다 : D 나는 질문을 한 후 한 시간 후에 답을 게시했습니다 :) – Christophe

답변

1

는 해결책을 발견 -> codeigniter.com/forums/viewthread/149027가 허용 된 MIME 타입에 강제 다운로드를 추가

0

나는 $ _FILES [ 'your_file_name'] [ '유형'에서 '응용 프로그램/octet-stream을'을 가지고 ], 그래서 'application/octet-stream'을 mime 형식에 'zip'(/config/mimes.php에 있음)에 추가해야했습니다.

$ _FILES [ 'your_file_name'] [ 'type']의 값은 브라우저/플랫폼에 따라 다를 수 있습니다.

관련 문제