CodeIgniter文件上传不起作用,没有给出错误

时间:2016-02-26 10:20:45

标签: codeigniter file-upload

我正在尝试从CodeIgniter上传文件。文件没有给出任何错误,甚至没有将文件存储在根目录或codeigniter中的uploads文件夹中。有人可以帮忙吗?请注意,因为我已经给了我的上传文件夹755的权限。下面是我的代码

查看文件

document.head.querySelector("[property~=video][content]").content;

以下是我的控制器

<html>
<head>
<title>Upload Form</title>
</head>
<body>

<?php echo $error;?>

<?php echo form_open_multipart('UploadController');?>

<input type="file" name="userfile" size="20" />

<br /><br />

<input type="submit" value="upload" />

</form>

</body>
</html>

请在这个问题上帮助我。

3 个答案:

答案 0 :(得分:0)

变化

form_open_multipart('UploadController')

form_open_multipart('UploadController/do_upload')

答案 1 :(得分:0)

您的代码中存在一些错误: 请更改以下行:

1.更改      form_open_multipart('UploadController')        form_open_multipart('UploadController/do_upload')

2.change   $this->upload->do_upload("add_1")     $this->upload->do_upload("userfile")。 3.change $this->load->view('upload_form', $error);   
   $this->load->view('uploadview', $error);

答案 2 :(得分:0)

更改表单操作路径

form_open_multipart( 'UploadController / do_upload')

或者您可以在一种方法中使用它:

function index()
{
    $config['upload_path']      = 'upload_path';
  $config['allowed_types']    = 'gif|jpg|jpeg|png';
  $config['max_size']         = 5120;
  $config['encrypt_name']     = true;

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

    $this->form_validation->set_rules('image', 'lang:image', 'file_size_max[5M]|file_allowed_type[image]');

    if($this->form_validation->run() == FALSE)
    {
        $this->load->view('uploadview', array('error' => ' ' ))
    }
    else
    {
        $user = array();

        $uploaded  = $this->upload->do_upload('add_1');

    //delete the original file if another is uploaded
    if($uploaded)
    {           
      $data = array('upload_data' => $this->upload->data());

      $this->load->view('uploadview', $data);
    } else {
      $error = array('error' => $this->upload->display_errors());

      $this->load->view('upload_form', $error);
    }
    }
}

确保您的上传路径正确。