使用codeigniter(3.1)上传文件失败

时间:2015-11-18 13:55:50

标签: php html codeigniter


我在使用Codeigniter框架上传文件时遇到问题。 目前正在这样工作:
如果我没有选择HTML格式的任何文件,那么svg等变量就会获得价值 但是当我以html格式选择文件时,所有变量都为空,我没有选择消息文件。

我的.htaccess文件

$title = $this->input->post('title');

我的autoload.php文件

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

我的控制器正在渲染视图:

$autoload['helper'] = array('url', 'file', 'form');
$autoload['libraries'] = array('database', 'session', 'email', 'form_validation');
$autoload['model'] = array('model_services' => 'ms', 'Model_categories' => 'mc');

HTML:

 public function add_catalog() {
        if ($this->is_admin() == TRUE) {
            $data['cat'] = $this->mc->get();
            $this->load->view('admin_view_map/admin_header');
            $this->load->view('admin_view_map/admin_add_catalog', $data);
            $this->load->view('admin_view_map/admin_footer');
        } else {
            $this->index();
        }
    }

PHP:

<?php echo form_open_multipart('admin321/insert_catalog'); ?>
    *title: <input type="text" name="title" />
    sub_title: <input type="text" name="sub_title" />
    Facebook url: <input type="text" name="facebookUrl" />
    Twitter url: <input type="text" name="twitterUrl" />
    Google +: <input type="text" name="googlePlus" />
    description: <input type="text" name="description" />
    pdf: </span> <input type="file" name="pdf" />
    categories:
    <select name="categories" >
        <?php foreach ($cat as $r) {
                echo '<option value=' . $r->id_category . ' >' . $r->category . '</option>';
        } ?>
    </select>
    <input type="submit" value="Add" class="submit">
<?php echo form_close(); ?>

这样做的结果如下:

public function insert_catalog(){
    $title = $this->input->post('title');
    $sub_title = $this->input->post('sub_title');
    $facebookUrl = $this->input->post('facebookUrl');
    $twitterUrl = $this->input->post('twitterUrl');
    $googlePlus = $this->input->post('googlePlus');
    $description = $this->input->post('description');
    $category = $this->input->post('categories');
    var_dump($title,$sub_title,$facebookUrl,$twitterUrl,$googlePlus,$description,$category);

    $config['upload_path'] = './assets/pdf/';
    $config['allowed_types'] = 'pdf';
    $this->load->library('upload', $config);

    if (!$this->upload->do_upload('pdf')){
        var_dump($this->upload->display_errors());
        die();
    }else{
        $pdf = array('upload_data' => $this->upload->data());
        var_dump($pdf);
        die();
    }

}

我正在使用WAMP服务器,这是我的php.ini配置

null
null
null
null
null
null
null
string '<p>You did not select a file to upload.</p>' (length=43)

3 个答案:

答案 0 :(得分:1)

我真的不明白。

<?php foreach ($cat as $r) {
        echo '<option value=' . $r->id_category . ' >' . $r->category . '</option>';
} ?>

你在这里回忆什么? 你从哪里得到$ cat?

答案 1 :(得分:1)

在控制器上加载form helper

function __construct(){

    parent::__construct();
    $this->load->helper('form');

}

答案 2 :(得分:1)

检查php.ini中关于上传配置的php安装设置

upload_max_filesize  = 10M
post_max_size  = 10M