我已经创建了一个帮助程序,它需要一些参数,并且应该上传一个文件,该功能适用于图像,但不适用于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