Image CodeIgniter上载错误:不允许您尝试上载的文件类型

Image CodeIgniter上载错误:不允许您尝试上载的文件类型,image,codeigniter,uploading,Image,Codeigniter,Uploading,每当我试图上传任何jpg或png图像文件时,就会出现这个错误 我的表格: <form action="/merchant/process_create" method="post" id="merchant_signup" enctype="multipart/form-data"> <?php echo form_label('Select Your Logo or Relevant Image:', 'image'); echo "<br />"; ?>

每当我试图上传任何jpg或png图像文件时,就会出现这个错误

我的表格:

<form action="/merchant/process_create" method="post" id="merchant_signup" enctype="multipart/form-data">
<?php
echo form_label('Select Your Logo or Relevant Image:', 'image');
echo "<br />";
?>
<input type="file" name="image" size="20" id="image" />
<?php
echo "<br />";
echo "<br />";

echo form_submit('submit', 'Create Account');
?>

控制器的上载部分:

//upload the image
$config['upload_path'] = $_SERVER['DOCUMENT_ROOT'] . '/uploads/';
$config['allowed_types'] = 'jpg|jpeg|gif|png';
$config['max_size'] = '2000';
$config['max_width']  = '0';
$config['max_height']  = '0';
$config['file_name']  = time() . rand();
$config['remove_spaces'] = TRUE;

$this->load->library('upload', $config);

if ( ! $this->upload->do_upload('image'))
{
    $data= array('error' => $this->upload->display_errors('', '<br />'));

    //reload the view
    $this->load->view('header');

    $this->load->view('merchant_create_form', $data);

    $this->load->view('footer');

}   else {

    //make the insert array
    $merchant_data = array(
        'user_id'           => $this->session->userdata('user_id'),
        'name'              => $this->input->post('name'),
        'uri_slug'          => $this->input->post('uri_slug'),......
//上传图像
$config['upload\u path']=$\u服务器['DOCUMENT\u ROOT']/上传/';
$config['allowed_types']='jpg | jpeg | gif | png';
$config['max_size']='2000';
$config['max_width']='0';
$config['max_height']='0';
$config['file_name']=time()。兰德();
$config['remove_spaces']=TRUE;
$this->load->library('upload',$config);
如果(!$this->upload->do_upload('image'))
{
$data=array('error'=>this->upload->display_errors('',
'); //重新加载视图 $this->load->view('header'); $this->load->view('merchant\u create\u form',$data); $this->load->view('footer'); }否则{ //创建插入数组 $merchant_数据=阵列( 'user\u id'=>this->session->userdata('user\u id'), 'name'=>this->input->post('name'), 'uri_slug'=>this->input->post('uri_slug'),。。。。。。
我不明白为什么有必要删除它…

注释掉这行,$config['file\u name']=time().rand(); 让我们知道发生了什么

//  $config['file_name']  = time() . rand();

检查application/config/mimes.php文件是否包含所需的mime类型在upload类的do_upload方法中,查看失败的地方。

您确定要测试的文件是实际的png或jpg文件吗?CI将在$config['allowed_types']中检查您上载的文件的MIME类型,而不仅仅是文件扩展名。您正在加载库,$this->load->library('upload'))?事实证明,当指定文件名配置时,您还必须向其附加文件扩展名。谢谢您的帮助!!-尼克·罗斯坎