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

时间:2011-01-13 16:36:45

标签: 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 />";
?>
<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'),......

3 个答案:

答案 0 :(得分:0)

我看不出为什么$config['file_name']需要尝试删除它...

答案 1 :(得分:0)

注释掉这行,$ config ['file_name'] = time()。兰特(); 让我们知道发生了什么。

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

答案 2 :(得分:0)

检查application / config / mimes.php文件是否包含您需要的mime类型。否则,开始将var_dump()放在Upload类的do_upload方法中,以查看失败的位置。