开发者

Help uploading a file with codeiginter

I am trying to upload a file using PHP and codeigniter. My problem is that I am getting an error returned

You did not select a file to upload.

I am using the following code,

    $config['upload_path'] = "./media/uploads/cv";
            $config['allowed_types'] = 'pdf|doc|docx';
            $config['max_size'] = '1000';

            $this->upload->initialize($config);
            $this->upload->do_upload('cvfile');
            if($this->upload->display_errors())
            {
                $data['error'] = $this->upload->display_errors();
                die(print_r($data['error']));
                $this->template->build('/users/candidate', $data);
                return;
            }
            else
            {
                die(print_r($this->upload->data()));
            }

In my HTML I have a multipart form and with in that form I am using the following code,

开发者_如何转开发
<input type="file" class="small" id="cvfile" value="" name="cvfile">

Why would I be getting the above error?


That says that the PHP function is_uploaded_file indicated that the upload file with the name cvfile didn't exist. You should check your multipart/form declaration and verify that it is valid, and make sure your PHP setup will allow you to write uploaded files to the temp folder.


View:

<?php echo form_open_multipart('home/.....');?>//going to next page 
      <input type="file" name="cvfile" />
</form>

Controller:

$config['upload_path']   = './path'; // put here your path 
$config['allowed_types'] = 'pdf|doc|docx';  
$config['max_size']      = '4096';      

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

if (!$this->upload->do_upload("cvfile")) {
    echo $this->upload->display_errors(); die();
    $this->data['error'] = array('error' => $this->upload->display_errors());
} else {
    $upload_result = $this->upload->data();
    print_r($upload_result['file_name']);//or print any valid
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜