我已經創建了一個幫助程序,它需要一些參數,並且應該上傳一個文件,該功能適用於圖像,但不適用於zip文件。我搜索谷歌和甚至增加了一個MY_upload.php - >http://codeigniter.com/bug_tracker/bug/6780/在codeigniter中上傳zip文件將不起作用
但是我仍然有問題,所以我用的print_r顯示上傳的文件的陣列,所述圖像是精細然而拉鍊數組爲空:
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;
找到解決方案 - > http://codeigniter.com/forums/viewthread/149027/ 將強制下載添加到允許的MIME類型 – Christophe 2010-04-27 07:53:53
您「應該」添加您的答案作爲答案並批准它, t出現在這裏的「未答覆」中。 :) – Robert 2010-04-29 07:41:54
是的,但你總是必須等待24小時,直到你可以做到這一點:D我問一個問題後,一個小時後我發佈了答案:) – Christophe 2010-04-29 13:29:37