我创建了一个需要一些参数并且应该上传文件的帮助程序,该函数适用于图像,但不适用于zip文件。我在谷歌搜索,甚至添加了MY_upload.php - > http://codeigniter.com/bug_tracker/bug/6780/
但是我仍然有问题所以我使用print_r来显示上传文件的数组,图像很好但是zip数组是空的:
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;
答案 0 :(得分:1)
找到了解决方案 - &gt; codeigniter.com/forums/viewthread/149027将强制下载添加到允许的mime类型
答案 1 :(得分:0)
我得到了&application; / octet-stream&#39;在$ _FILES [&#39; your_file_name&#39;] [&#39; type&#39;]中,所以我必须添加&#39; application / octet-stream&#39;用于&#39; zip&#39;的mime类型(在/config/mimes.php中)。
$ _FILES [&#39; your_file_name&#39;] [&#39; type&#39;]的值似乎因浏览器/平台而异。